Phazie Posted March 11, 2010 Share Posted March 11, 2010 hello! since im pretty noob @ PHP then i would request some help from pro's ok, here's the thing - i have 2 seperate codes and i want em to have together in 1 file so while i upload image it already resizes also or atleast if it has uploaded then it resizes image(s) Code 1 ------ upload form <form enctype="multipart/form-data" action="upload.php" method="post"> Pilt 1: <input name="userfile[]" type="file" class="texta" /><br /> Pilt 2: <input name="userfile[]" type="file" class="texta" /><br /> Pilt 3: <input name="userfile[]" type="file" class="texta" /><br /> Pilt 4: <input name="userfile[]" type="file" class="texta" /><br /> <input type="submit" class="texta" value="Lae üles" /> </form> <?php $success = 0; $fail = 0; $uploaddir = 'gallery/'; for ($i=0;$i<4;$i++) { if($_FILES['userfile']['name'][$i]) { $uploadfile = $uploaddir . basename($_FILES['userfile']['name'][$i]); $ext = strtolower(substr($uploadfile,strlen($uploadfile)-3,3)); if (preg_match("/(jpg|gif|png|bmp)/",$ext)) { if (move_uploaded_file($_FILES['userfile']['tmp_name'][$i], $uploadfile)) { $success++; } else { echo "Ei saa üles laadida, proovi hetke pärast uuesti.\n"; $fail++; } } else { $fail++; } } } echo "<br> Faile üles laetud:".$success; echo "<br> Ebaõnnestunud faile:".$fail; ?> Code 2 ------ resize function resize($filename) { $width = 760; $height = 600; list($width_orig, $height_orig) = getimagesize($filename.".jpg"); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($filename.".jpg"); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); if(imagejpeg($image_p, $filename."-tn.jpg", 100)) { return 1; } else { return 0; } } maybe some1 is so kind and fits them together Link to comment https://forums.phpfreaks.com/topic/194898-multiple-image-upload-resize/ Share on other sites More sharing options...
Phazie Posted March 13, 2010 Author Share Posted March 13, 2010 no1? Link to comment https://forums.phpfreaks.com/topic/194898-multiple-image-upload-resize/#findComment-1025594 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.