Jump to content

zander1983

Members
  • Posts

    43
  • Joined

  • Last visited

    Never

Everything posted by zander1983

  1. but this will give diffrerent new height for each image. i need it like etsy.com where every image has same width and height...
  2. Hi Im working on a market place style website. the framework im using is called elgg. it uses an algoritm to find the right approximate width and height of an image thats being uploaded. but on my site, all heights and widths must be the same. this is difficult because some pictures have much greater width than height and some have much greater height. so whats the best algoritm to use to make an accurate thumbnail of all images uploaded? Thanks
  3. Hi I have an array which looks like this when i do a print_r(): Array ( [0] => Array ( [path] => 1 [order] => 2 ) [1] => Array ( [path] => 2 [order] => 1 ) [2] => Array ( [path] => 3 [order] => 2 ) ) In this instance, I want to change the values of the order key. So I do something like this so that the last array has a path of 3 and an order of 1, and the others have orders of 2 foreach ($old_images as $old_image){ if($old_image['path']==3){ $old_image['order']="1"; } else{ $old_image['order']="2"; } } When i step through, i see that the order is changed, but when i do a print_r(), i get the same result. So even though im resetting the order value of the inside arrays, the multidimensional array does not change.... any ideas?
  4. got it, i used this: <?php // Sort the multidimensional array usort($results, "custom_sort"); // Define the custom sort function function custom_sort($a,$b) { return $a['some_sub_var']>$b['some_sub_var']; } ?>
  5. I have an array and when i do a print_r(), i get this: Array ( [0] => Array ( [path] => 1 [order] => 2 ) [1] => Array ( [path] => 2 [order] => 2 ) [2] => Array ( [path] => 3 [order] => 1 ) ) I want to sort it so that the array with an order of 1 is at the front, i.e. that last array in this case. I tried asort but that didnt do anything...
  6. Hi I want to allow users to upload multiple pictures and allow the user to rearrange the order before being uploaded. I have some javascript which populates a select tag with the image names after selecting an image to upload, and some other javascript that allows the users to move the options up and down the list. So it ouputs code such as this to user if they have selected 2 image files for uploading: <select size="6" id="file_list" name="file_list"> <option value="file_0">DSCN2794.JPG</option> <option value="file_1">DSCN2787.JPG</option> </select> I dont know if this is the correct way of approaching it because then in the back end, I use $_FILES, which doesn't care what order the options are in the select tag.... Any advice? Thanks!
  7. @neil.johnson Thanks for that, thats a pretty comprehensive answer. You seem to be more pro framework than against it. Are there any you recommend? We have being using Elgg. One problem I've noticed amongst our develoeprs (including myself) is when we have a problem, we investigate whether its been done before (amost always yes), and then adapt that solution to suit our problem. With Elgg (and Im assuming all frameworks), we have to adapt the soltiuon to fit our problem, then adapt this solution to fit into the framework. With Elgg, this can lead to hours fighting with vews and actions and registering actions etc. Is this an issue with other frameworks? I have a website which i coded from scratch. Im considering that we use this code base rather than wrestling with Elgg. Heres the site if you're interested: http://www.cottageireland.ie
  8. Is coding from scratch really better though? We have 3 developers and the boss believes we should use a framework because: 1 nobody codes large online applications from scratch anymore (his words) 2 its more stable 3 it forces the different developers to code within certain parameters thereby having a more uniform code base 4 easier to continually add features to the site because of the framework I have always been a code from scratch person. But the arguments for frameworks are growing, especially regarding stability
  9. Just wondering how many people recommend using a framework, such as cakePhp, or coding from scratch? I always coded from scratch, but tried using a Php framework recently called Elgg. It was an absolute nightmare. so how many code from scratch? and how many people use a framework?
  10. ok thanks, im going to keep reading and try to follow these principles:) thanks for help
  11. Hi mjdamato Thanks for your response and you make some interesting points. What is your view on the MVC model? I've been reading this article http://www.phppatterns.com/docs/design/archive/model_view_controller_pattern I have tended to write more procedural code, but the MVC model talks about layers of seperation within code. I dont even use object oriented programming when writing PHP code (I used to in .NET but have gotten out of the habit). The the MVC model and OOP the way to go when writing modern php code? As I expect this site to go live in a few months and have a fairly heavy traffic load, I want to get the structure and style of the code right... Thanks Mark
  12. Hi I've developed a website myself over the last 6 months. I've gotten some investment to develop it further and will now have 2 develoeprs working with me. Its a market place style website so high hits are expected and speed is a must. I was wondering, is my code up to scratch? what exactly are best practices in php? Here's an example of how i get all products on the index page: $sql = "SELECT si.Name, si.ShopItemID, si.Active, si.InStock, si.DateAdded, si.Price, s.CountyID, si.Url as ItemUrl, s.Url as ShopUrl, si.Approved, ii.Url, ii.Active, ii.Front, ii.Thumb, ii.OrderImage, s.CategoryID, s.ShopID, s.Active "; $sql = $sql."FROM shopitem si "; $sql = $sql."Inner Join shop s On (s.ShopID = si.ShopID) "; $sql = $sql."left Join itemimage ii on (ii.ShopItemID = si.ShopItemID And ii.OrderImage = 1) Where 1=1 and si.Active = 1 and si.InStock > 0 and s.Active = 1 and si.Approved = 1 "; if(!$categoryId==0 and !$categoryId==""){ $sql = $sql."And CategoryID = ".mysql_real_escape_string($categoryId); } $sql .= " Group By si.ShopItemID "; and to display it: while ($row = mysql_fetch_array($result)) { echo "<div class='shopItems'>"; echo "<div id='itemIndex'>".$x.".</div>"; if(!$row['Url']==NULL){ echo "<div id='centered'><a href='".WEBSITE_DOMAIN."shops/".$row['ShopUrl']."/".$row['ItemUrl']."'><img alt='".htmlspecialchars($row['Name'])."' title='".htmlspecialchars($row['Name'])."' height='135' width='170' src='images/".htmlspecialchars($row['Front'])."'/></a></div>"; } else{ echo "<div id='centered'><a href='".WEBSITE_DOMAIN."shops/".$row['ShopUrl']."/".$row['ItemUrl']."'><img alt='".htmlspecialchars($row['Name'])."' title='".htmlspecialchars($row['Name'])."' height='135' width='170' src='images/no-img.jpg'/></a></div>"; } echo "<div id='centered'><a href='".WEBSITE_DOMAIN."shops/".$row['ShopUrl']."/".$row['ItemUrl']."'>".htmlspecialchars($row['Name'])."</a></div>"; echo "<p id='centered'>€".htmlspecialchars($row['Price'])."</p>"; echo "</div>"; If($x%4==0){ echo "<div id='clear'></div>"; echo "<div id='divider'></div>"; } $x++; } Is there anything wrong with this approach? Is it best practice and/or faster to use object oriented programming? So I would have a ShopItems class, with members which reflect the attributes of the ShopItems table, and call a function of it to run the sql and set the vales of the members. Am I going in the right direction, towards better practices? Or is what I have done fine? I have used the top approach throught the website, but worry that its a bit of an old-fashioned approach...any advice? thanks Mark
  13. You should use an array. For example: for($i = 0; $i < 10; $i++){ $arr[$i] = "some text ".$i; } echo $arr[5];
  14. I have a SSL Cert for my site. I've put all the files from the http folder to the https folder. What is normally done to redirect people to the https folder? Do i use a url rewrite rule in the .htaccess folder so everytime someone is looking at a http page, its actually a https page?
  15. i had not thought about that, this must be the problem, cheers
  16. I've got a market place style site and a friend managed to perform SQL injection on it despite the fact I use mysql_real_escape_string() to escape any dodgy characters. Are there any flaws to this function? I thought it totally eradicated SQL injection..
  17. Hi I was wondering, what are the main fundamental security features which should be in place on a php website? I have an e-commerce site i hope to launch soon, and the security measures i use are: 1. SSL 2. Any data from user is cleansed with mysql_real_escape_string() before being inserted to a table 3. MD5 + salt used to encrypt passwords Am I missing anything? Is this enough? With database tables, do I only need to encrypt password fields? Are all other field ok as they are? Regarding sessions, i use them a lot throughout the site. Are there any security issues here? Cheers Mark
  18. Hi Im developing a marketplace style site. There are 3 steps for the person to go through before confirming a purchase i.e. postage, shipping details and payment details pages. What is the best way for remembering a users data as they go through the process? At the moment, I do something like this for the postage page: $_SESSION['Post']['PostTypeID'] = $postType $_SESSION['Post']['TotalPrice'] = $totalPrice I use more session values for the other pages. Is this the best method? The session variable can get quite large.... Also, a few years ago when i was doing .net, we would create a Class at the start of the checkout process, and then pass the class through and set the different attributes e.g. shippingAddress1, totalPrice etc. Is it possible to do something like this in php?
  19. ya ive done that. what i also meant to ask is SSL necessary?
  20. Hi Ive got a site almost ready to go but my friend just pointed out that i should be using SSL to secure and encrypt data. Its a php site running on apache. anybody any ideas where I start with SSL?
  21. i've got this form <form method="post" name="imageForm" enctype="multipart/form-data" action=""> <label> <span class="labelText">Images</span> <input name="file" type="file" /> <span class="labelText"> </span> <input name="SubmitImg" type="submit" value="Upload" /> </label> </form> at the top of page, i have: if(isset($_POST['SubmitImg'])) { echo uploadImages("file", "", MAX_WIDTH, "./images/", $shopItemId); } So once the user clicks "Upload", the page submits and goes into the Post clause. Now i want to submit the page using javascript onchange and go into the Post clause. Im using onchange to call the function: function submitform() { document.imageForm.submit(); } The page submits but does not go into Post clause...
  22. the function is function uploadImage($fileName, $maxSize, $maxW, $fullPath, $relPath, $colorR, $colorG, $colorB, $maxH = null, $func, $shopItemId){ $folder = $relPath; $maxlimit = $maxSize; $allowed_ext = "jpg,jpeg,gif,png,bmp"; $match = ""; $filesize = $_FILES[$fileName]['size']; if($filesize > 0){ $filename = strtolower($_FILES[$fileName]['name']); $filename = preg_replace('/\s/', '_', $filename); if($filesize < 1){ $errorList[] = "File size is empty."; } if($filesize > $maxlimit){ $errorList[] = "File size is too big."; } $file_ext = preg_split("/\./",$filename); $allowed_ext = preg_split("/\,/",$allowed_ext); foreach($allowed_ext as $ext){ if($ext==end($file_ext)){ $match = "1"; // File is allowed $NUM = time(); $front_name = substr($file_ext[0], 0, 15); $newfilename = $front_name."_".$NUM.".".end($file_ext); $newthumbname = $front_name."_".$NUM."_s.".end($file_ext); $newfrontname = $front_name."_".$NUM."_f.".end($file_ext); $_SESSION[] = $newfilename; $filetype = end($file_ext); $save = $folder.$newfilename; $savethumb = $folder.$newthumbname; $savefront = $folder.$newfrontname; if(!file_exists($save)){ list($width_orig, $height_orig) = getimagesize($_FILES[$fileName]['tmp_name']); if($maxH == null){ if($width_orig < $maxW){ $fwidth = $width_orig; }else{ $fwidth = $maxW; } $ratio_orig = $width_orig/$height_orig; $fheight = $fwidth/$ratio_orig; $blank_height = $fheight; $top_offset = 0; }else{ if($width_orig <= $maxW && $height_orig <= $maxH){ $fheight = $height_orig; $fwidth = $width_orig; }else{ if($width_orig > $maxW){ $ratio = ($width_orig / $maxW); $fwidth = $maxW; $fheight = ($height_orig / $ratio); if($fheight > $maxH){ $ratio = ($fheight / $maxH); $fheight = $maxH; $fwidth = ($fwidth / $ratio); } } if($height_orig > $maxH){ $ratio = ($height_orig / $maxH); $fheight = $maxH; $fwidth = ($width_orig / $ratio); if($fwidth > $maxW){ $ratio = ($fwidth / $maxW); $fwidth = $maxW; $fheight = ($fheight / $ratio); } } } if($fheight == 0 || $fwidth == 0 || $height_orig == 0 || $width_orig == 0){ die("FATAL ERROR REPORT ERROR CODE [add-pic-line-67-orig] to <a href='http://www.atwebresults.com'>AT WEB RESULTS</a>"); } if($fheight < 45){ $blank_height = 45; $top_offset = round(($blank_height - $fheight)/2); }else{ $blank_height = $fheight; } } $newwidth = 75; // This can be a set value or a percentage of original size ($width) $newheight = 75; // This can be a set value or a percentage of original size ($height) $frontheight = 135; $frontwidth = 170; // Load the images $thumb = imagecreatetruecolor($newwidth, $newheight); $front = imagecreatetruecolor($frontwidth, $frontheight); $image_p = imagecreatetruecolor($fwidth, $blank_height); $white = imagecolorallocate($image_p, $colorR, $colorG, $colorB); imagefill($image_p, 0, 0, $white); switch($filetype){ case "gif": $image = @imagecreatefromgif($_FILES[$fileName]['tmp_name']); break; case "jpg": $image = @imagecreatefromjpeg($_FILES[$fileName]['tmp_name']); break; case "jpeg": $image = @imagecreatefromjpeg($_FILES[$fileName]['tmp_name']); break; case "png": $image = @imagecreatefrompng($_FILES[$fileName]['tmp_name']); break; } @imagecopyresampled($image_p, $image, 0, $top_offset, 0, 0, $fwidth, $fheight, $width_orig, $height_orig); // Resize the $thumb image. @imagecopyresized($thumb, $image, 0, 0, 0, 0, $newwidth, $newheight, $width_orig, $height_orig); // Resize the $thumb image. @imagecopyresized($front, $image, 0, 0, 0, 0, $frontwidth, $frontheight, $width_orig, $height_orig); switch($filetype){ case "gif": if(!@imagegif($image_p, $save)){ $errorList[]= "PERMISSION DENIED [GIF]"; } if(!@imagegif($thumb, $savethumb)){ $errorList[]= "PERMISSION DENIED [GIF]"; } if(!@imagegif($front, $savefront)){ $errorList[]= "PERMISSION DENIED [GIF]"; } break; case "jpg": if(!@imagejpeg($image_p, $save, 100)){ $errorList[]= "PERMISSION DENIED [JPG]"; } if(!@imagejpeg($thumb, $savethumb, 100)){ $errorList[]= "PERMISSION DENIED [JPG]"; } if(!@imagejpeg($front, $savefront, 100)){ $errorList[]= "PERMISSION DENIED [JPG]"; } else{ $var = "in the else "; } break; case "jpeg": if(!@imagejpeg($image_p, $save, 100)){ $errorList[]= "PERMISSION DENIED [JPEG]"; } if(!@imagejpeg($thumb, $savethumb, 100)){ $errorList[]= "PERMISSION DENIED [JPEG]"; } if(!@imagejpeg($front, $savefront, 100)){ $errorList[]= "PERMISSION DENIED [JPEG]"; } break; case "png": if(!@imagepng($image_p, $save, 0)){ $errorList[]= "PERMISSION DENIED [PNG]"; } if(!@imagepng($thumb, $savethumb, 0)){ $errorList[]= "PERMISSION DENIED [PNG]"; } if(!@imagepng($front, $savefront, 0)){ $errorList[]= "PERMISSION DENIED [PNG]"; } break; } @imagedestroy($filename); }else{ $errorList[]= "CANNOT MAKE IMAGE IT ALREADY EXISTS"; } } } }else{ $errorList[]= "NO FILE SELECTED"; } if(!$match){ $errorList[]= "File type isn't allowed: $filename"; } if(sizeof($errorList) == 0){ return $fullPath.$newfilename; }else{ $eMessage = array(); for ($x=0; $x<sizeof($errorList); $x++){ $eMessage[] = $errorList[$x]; } return $eMessage; } } when i use ajax to call this, no problem. the 3 pictures upload. when i use a regular call, @imagejpeg returns false.....
  23. Im using imagejpeg to upload images. it works fine when i do a call using javascript and ajax. but when i call normally, with a page reload, it always returns false....very very frustrating as the exact same code will only work from an ajax call. anyone any idea?
  24. that worked, thanks. Ive been using header(location) for years without knowing this! thanks!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.