0

I am using an upload script that is working great:

ini_set('memory_limit', '256M');
function uploadImage($files_name, $files_tmp_name, $files_error, $files_type, $uploaded_photos_array, $image_type, $replace_position='69') { //Checks if the file uploaded correctly, saves the folder name to the DB, and calls the resizeAndPlaceFile 3 times 
 global $address;
 //If the directory doesn't exist, create it
 if (!is_dir('../images/uploads/temp/'.$address)) {
 mkdir('../images/uploads/temp/'.$address);
 }
 $myFile_original = $files_name; //Store the filename into a variable
 //Change the filename so it is unique and doesn't contain any spaces and is all lowercase
 $myFile = str_replace(' ', '_', $myFile_original); //change all spaces to underscores within a file name
 $myFile = strtolower($myFile); //Make all characters lowercase
 //$anyNum = rand(20,500789000); //Generate a random number between 20 and 500789000 
 //$newFileName = $anyNum.'_'.$myFile; //Combine the random number with the filename to create a unique filename
 $newFileName = $myFile;
 $info = pathinfo($newFileName); //Finds the extension of the filename
 $directory_name = basename($newFileName,'.'.$info['extension']); //Removes the extension from the filename to use as the name of the directory
 $folder = '../images/uploads/temp/'.$address.'/'.$directory_name.'/'; //Folder to upload to
 //If the directory doesn't exist, create it
 if (!is_dir($folder)) {
 mkdir($folder);
 }
 //===Check if the File already exists======== 
 if (file_exists($folder.'large.jpg')) {
 echo $myFile_original." already exists.";
 } //******If file already exists in your Folder, It will return zero and Will not take any action===
 else { //======Otherwise File will be stored in your given directory and Will store its name in Database===
 //copy($_FILES['fileField']['tmp_name'],$folder.$newFileName); //===Copy File Into your given Directory,copy(Source,Destination)
 // Check if file was uploaded ok
 if(!is_uploaded_file($files_tmp_name) || $files_error !== UPLOAD_ERR_OK) {
 exit('There was a problem uploading the file. Please try again.');
 } else {
 /*
 $sql = 'INSERT into tblfileupload SET
 file_name = "'.$folder.'"'; 
 $result = $conn->query($sql) or die($conn->error);
 if($result > 0) { //====$res will be greater than 0 only when File is uploaded Successfully====:)
 echo 'You have Successfully Uploaded File';
 }
 */
 if(!function_exists('resizeAndPlaceFile')){
 function resizeAndPlaceFile($image_size, $files_tmp_name, $files_type, $folder) { //Resizes the uploaded file into different sizes
 //echo '<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />The resizeAndPlaceFile function is being called!';
 // Create image from file
 switch(strtolower($files_type)) {
 case 'image/jpeg':
 $image = imagecreatefromjpeg($files_tmp_name);
 break;
 case 'image/png':
 $image = imagecreatefrompng($files_tmp_name);
 break;
 case 'image/gif':
 $image = imagecreatefromgif($files_tmp_name);
 break;
 default:
 exit('Unsupported type: '.$files_type);
 }
 // Get current dimensions
 $old_width = imagesx($image);
 $old_height = imagesy($image);
 // Target dimensions for large version
 switch($image_size) {
 case 'large':
 $max_width = '600'; //Large Photo (Listing Page)
 break;
 case 'medium':
 $max_width = '157'; //Medium Photo (Dashboard)
 break;
 case 'thumbnail':
 $max_width = '79'; //Small Photo (Listing Page - Thumbnail)
 break;
 }
 if($max_width > $old_width) {
 $max_width = $old_width;
 }
 $max_height = ($old_height/$old_width)* $max_width;
 // Get current dimensions
 $old_width = imagesx($image);
 $old_height = imagesy($image);
 // Calculate the scaling we need to do to fit the image inside our frame
 $scale = min($max_width/$old_width, $max_height/$old_height);
 // Get the new dimensions
 $new_width = ceil($scale*$old_width);
 $new_height = ceil($scale*$old_height);
 // Create new empty image
 $new = imagecreatetruecolor($new_width, $new_height);
 // Resize old image into new
 imagecopyresampled($new, $image, 0, 0, 0, 0, $new_width, $new_height, $old_width, $old_height);
 //Output the image to a file
 imagejpeg($new, $folder.$image_size.'.jpg',100);
 // Destroy resources
 imagedestroy($image);
 imagedestroy($new);
 } //end function resizeAndPlaceFile
 } //end if !function_exists['resizeAndPlaceFile']
 resizeAndPlaceFile('large',$files_tmp_name, $files_type, $folder); //Large Photo (List Page)
 resizeAndPlaceFile('medium',$files_tmp_name, $files_type, $folder); //Medium Photo (Dashboard)
 resizeAndPlaceFile('thumbnail',$files_tmp_name, $files_type, $folder); //Small Photo (List Page - Thumbnail)
 if($image_type == 'replace') { //If this is being run for a replace, then replace one of the values instead of adding it to the end of the array
 $uploaded_photos_array[$replace_position] = $folder; //This replaces the value of the old image with the new image
 } else if($image_type == 'initial') { //otherwise, add it to the end of the array
 array_push($uploaded_photos_array,$folder);
 }
 return $uploaded_photos_array;
 } //end else 
 } //end else
} //end function uploadImage

When I try to upload any file above 2.1mb, it won't upload the file and won't display any error so I have no idea why it is not working. Why will my upload form not upload files over 2.1mb using php?

asked Jun 19, 2012 at 6:30
1

3 Answers 3

3

Check and change the following php.ini instructions:

memory_limit = 32M
upload_max_filesize = 10M
post_max_size = 20M
answered Jun 19, 2012 at 6:33
Sign up to request clarification or add additional context in comments.

Comments

1

update these parameters in your php.ini

upload_max_filesize
post_max_size
answered Jun 19, 2012 at 6:32

Comments

0

You can't change maximum file upload size from your php script. You should change in php.ini file as upload_max_filesize = 30M post_max_size = 30M

Some hosters dosen't allow to change php.ini(in case of shared hosting) in that u should use .htaccess and use following php_value upload_max_filesize 30M

answered Jun 19, 2012 at 6:42

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.