wrathican Posted July 23, 2008 Share Posted July 23, 2008 hey people ive recently made a scrpit that uploads an image to a server then makes 2 images from it then deletes the original image. when i test it on my localhost everything is fine no matter how big the image is(file size wise). the most i have tested it at is 1.8Mb however when i test it live the picture gets uploaded but then the script just seems to stop. using smaller images works just fine. i did phpinfo to see what some values were and here they are: memory_limit 16M post_max_size 8M upload_max_filesize 2M max_execution_time 30 could it be that my script only has enough time to upload the picture before it times out? these are all the 'limit's that would effect my script as far as i know my server has E_ALL and no errors are outputted. if any of these 'limits' were stopping it from working, how would i change them(without access to php.ini)? this is my script: <?php //include files include "../includes/misc.php"; include "../includes/opendb.php"; include "../includes/functions.php"; //start session session_start(); //array & variable declaration $errorarray = array(); //used to store error messages $alId = $_POST['album']; $image = $_FILES['image']; $tmpImage = $image['tmp_name']; $imgImage = $image['name']; if (!empty($tmpImage[0])) { foreach($tmpImage as $K => $img){ if(!empty($img)) { //process the image upload $upload = uploadFile($img, $imgImage[$K], $tmpImg); if($upload == false) { $_SESSION['errorstate'] = 1; $errorarray[] = "Sorry, but the file you selected has not been uploaded. please try again later."; }else{ //make thumb $thumb = createThumb($upload, $thumbWidth, $thumbImg); if ($thumb == false) { $_SESSION['errorstate'] = 1; $errorarray[] = "Sorry, but the thumbnail could not be created. Please try again later."; unlink($upload); }else{ $smallerVer = createThumb($upload, $maxWidth, $galleryImg); if($smallerVer == false) { $_SESSION['errorstate'] = 1; $errorarray[] = "Sorry, but the small image was not created. Please try again later"; unlink($upload); unlink($thumb); }else{ $thumbLoc = substr($thumb, 2); $imageLoc = substr($smallerVer, 2); $query = "INSERT INTO won_picture (pic_image, pic_thumb, pic_albumid) VALUES('".$imageLoc."', '".$thumbLoc."', '".$alId."')"; $result = query($query); if($result == false) { $_SESSION['errorstate'] = 1; $errorarray[] = "Sorry, but the image was not added to the album. Please try again later"; unlink($upload); unlink($thumb); unlink($smallerVer); }else{ $_SESSION['errorstate'] = 1; $errorarray[] = "Thank you, the images you had select have been uploaded and added to the album."; echo $_SESSION['errormessage'] = $errorarray; header('Location: ../admin/galleryadmin.php?func=addimage'); } } } } } } }else{ $_SESSION['errorstate'] = 1; $errorarray[] = "Please select an image to upload."; echo $_SESSION['errormessage'] = $errorarray; header('Location: ../admin/galleryadmin.php?func=addimage'); } ?> these are the functions that i use: <?php //uploads a files to the server function uploadFile ($oldFile, $userFile, $imgDir) { //extensions array $validExt = array ('.jpg', '.jpeg', '.png', '.gif'); //get the file ext $ext = strrchr($userFile, "."); $ext = strtolower($ext); //check the file ext against the array if(in_array($ext, $validExt)) { //needle is in haystack //process upload //rename the file $newName = md5(rand() * time()) . $ext; //new file dest $destFile = $imgDir . $newName; //move the file to tmpDir $result = move_uploaded_file($oldFile, $destFile); if($result == false) { //there was an error uploading return false; }else{ //file was uploaded //chmod($destFile, 0777); return $destFile; } }else{ //needle is not in haystack. exit return false; } } function createThumb($result, $picWidth, $imgDir) { $poo = array(); if ($result == false) { //file could not be uploaded $poo[0] = false; $poo[1] = 1; return $poo; }else{ //file was uploaded. create thumbnail //pathinfo $file = pathinfo($result); //find the .ext $ext = $file['extension']; //strip .ext to lower $ext = strtolower($ext); //get image sizes $sizes = getimagesize($result); //ratio $ratio = $sizes[0]/$sizes[1]; //LS or PO if($sizes[0] > $sizes[1]){ //pic is landscape $newWidth = $picWidth; $newHeight = round($picWidth/$ratio); }else{ //pic is portrait $newWidth = round($picWidth*$ratio); $newHeight = $picWidth; } //create true colour image $srcImg = imagecreatetruecolor($newWidth, $newHeight); if($ext == 'jpg' || $ext == 'jpeg') { $tmpImg = imagecreatefromjpeg($result); }elseif($ext == 'png') { $tmpImg = imagecreatefrompng($result); }elseif($ext == 'gif') { $tmpImg = imagecreatefromgif($result); }else{ $poo[0] = false; $poo[1] = 2; return $poo; } //create destination image filename //get filename $name = $file['basename']; //dest filename $dstFile = $imgDir . $name; imagecopyresampled($srcImg, $tmpImg, 0, 0, 0, 0, $newWidth, $newHeight, $sizes[0], $sizes[1]); //save image if($ext == 'jpg' || $ext == 'jpeg') { imagejpeg($srcImg, $dstFile, 100); }elseif($ext == 'png') { imagepng($scrImg, $dstFile, 100); }elseif($ext == 'gif') { imagegif($srcImg, $dstFile, 100); }else{ $poo[0] = false; $poo[1] = 3; return $poo;; } $killSrc = imagedestroy($srcImg); $killTmp = imagedestroy($tmpImg); if($killSrc != false && $killTmp != false){ return $dstFile; }else{ $poo[0] = false; $poo[1] = 5; return $poo; } } } ?> thanks! Quote Link to comment https://forums.phpfreaks.com/topic/116159-solved-uploading-multiple-large-files/ Share on other sites More sharing options...
ignace Posted July 23, 2008 Share Posted July 23, 2008 nope, your getting out of memory_limit if you are allowed to adjust php settings, do: ini_set("memory_limit", "32M"); Quote Link to comment https://forums.phpfreaks.com/topic/116159-solved-uploading-multiple-large-files/#findComment-597349 Share on other sites More sharing options...
wrathican Posted July 23, 2008 Author Share Posted July 23, 2008 excellent, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/116159-solved-uploading-multiple-large-files/#findComment-597368 Share on other sites More sharing options...
wrathican Posted July 23, 2008 Author Share Posted July 23, 2008 hmm i guess you can't set max_post_size? Quote Link to comment https://forums.phpfreaks.com/topic/116159-solved-uploading-multiple-large-files/#findComment-597375 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.