Jump to content

[SOLVED] File upload help (max file size)


BarneyJoe

Recommended Posts

Hope someone can help with this. Have a file upload script that all seemed to be working fine, using the PHP component that resizes images (forget it's name).

 

So it checks the file name is unique, checks it's a jpg, gif, bmp or photoshop file as requires, and has a max file size line to limit it's size.

 

However, it seems that with any file over around 2MB, it's not uploading, and we're getting the error about it not being a jpg or gif.

 

The line in the upload page is :

 

<input name="uploadFile" type="file" size="55">
<input type="hidden" name="MAX_FILE_SIZE" value="80000" />

 

It did have a default value of 25000 but I changed it to 80000, but still the same problem.

 

Some code from the validation page :

 

$ValidationFailed = false;

if (($_FILES["uploadFile"]["type"] == "image/gif") 
|| ($_FILES["uploadFile"]["type"] == "image/pjpeg")
|| ($_FILES["uploadFile"]["type"] == "image/tif")
|| ($_FILES["uploadFile"]["type"] == "image/png")
|| ($_FILES["uploadFile"]["type"] == "image/photoshop")
|| ($_FILES["uploadFile"]["type"] == "image/bmp")) 
  { 
  if ($_FILES["uploadFile"]["error"] > 0) 
    { 
     $ValidationFailed = true; 
     $FTGvalid_file_errmsg = "Error: " . $_FILES["file"]["error"]; 
     $ErrorList .= $FTGvalid_file_errmsg . '<br/>'; 
    } 
  } 
else 
  { 
  $ValidationFailed = true; 
  $FTGvalid_file_errmsg = "Please select a valid image file type. The library supports .jpg, .gif, and .png files."; 
  $ErrorList .= $FTGvalid_file_errmsg . '<br/>'; 
  }
  
if (!empty($_FILES['uploadFile']['name']) && file_exists("Photos/" . $_FILES["uploadFile"]["name"]) && is_file('Photos/' . $_FILES['uploadFile']['name'])) 
{ 
  $ValidationFailed = true; 
  $FTGvalid_file_errmsg = "This file has already been uploaded. If you are sure it's a new photo please rename it before uploading to the library."; 
  $ErrorList .= $FTGvalid_file_errmsg . '<br/>'; 
    } 

 

Any ideas?

 

Link to comment
https://forums.phpfreaks.com/topic/45687-solved-file-upload-help-max-file-size/
Share on other sites

Cheers guys - I found the upload_max_filesize in php.ini, and sure enough it was 2M - I changed it to 8M, but still getting the

 

'Please select a valid image file type. The library supports .jpg, .gif, and .png files.' error message.

 

Where should I try the

 

ini_get('upload_max_filesize',10000000);

 

line - the addphoto page, or the validation script?

put it in the uploader script it will change the maximum upload size in the php.ini file

and it will be ini_set('upload_max_filesize',whateversizeinbytes);

it will need to be in the upload script because once the script is done executing it will reset back to its default value

OK - didn't spot that set instead of get there.

 

I popped it in at the top of that part, ie :

 

# Fields Validations

ini_set('upload_max_filesize',10000000);

$ValidationFailed = false;

if (($_FILES["uploadFile"]["type"] == "image/gif") 
|| ($_FILES["uploadFile"]["type"] == "image/pjpeg")
|| ($_FILES["uploadFile"]["type"] == "image/tif")
|| ($_FILES["uploadFile"]["type"] == "image/png")
|| ($_FILES["uploadFile"]["type"] == "image/photoshop")
|| ($_FILES["uploadFile"]["type"] == "image/bmp")) 
  { 
  if ($_FILES["uploadFile"]["error"] > 0) 
    { 
     $ValidationFailed = true; 
     $FTGvalid_file_errmsg = "Error: " . $_FILES["file"]["error"]; 
     $ErrorList .= $FTGvalid_file_errmsg . '<br/>'; 
    } 
  } 
else 
  { 
  $ValidationFailed = true; 
  $FTGvalid_file_errmsg = "Please select a valid image file type. The library supports .jpg, .gif, and .png files."; 
  $ErrorList .= $FTGvalid_file_errmsg . '<br/>'; 
  }


if (!empty($_FILES['uploadFile']['name']) && file_exists("Photos/" . $_FILES["uploadFile"]["name"]) && is_file('Photos/' . $_FILES['uploadFile']['name'])) 
{ 
  $ValidationFailed = true; 
  $FTGvalid_file_errmsg = "This file has already been uploaded. If you are sure it's a new photo please rename it before uploading to the library."; 
  $ErrorList .= $FTGvalid_file_errmsg . '<br/>'; 
    } 

 

...but still getting the

 

Please select a valid image file type. The library supports .jpg, .gif, and .png files.

 

error.

Where should I try the

 

ini_get('upload_max_filesize',10000000); - At biggining of file where upload script is written.

 

 

Cheers guys - I found the upload_max_filesize in php.ini, and sure enough it was 2M - I changed it to 8M, but still getting the

 

'Please select a valid image file type. The library supports .jpg, .gif, and .png files.' error message.

 

Where should I try the

 

ini_get('upload_max_filesize',10000000);

 

line - the addphoto page, or the validation script?

change

 

if (($_FILES["uploadFile"]["type"] == "image/gif") 
|| ($_FILES["uploadFile"]["type"] == "image/pjpeg")
|| ($_FILES["uploadFile"]["type"] == "image/tif")
|| ($_FILES["uploadFile"]["type"] == "image/png")
|| ($_FILES["uploadFile"]["type"] == "image/photoshop")
|| ($_FILES["uploadFile"]["type"] == "image/bmp")) 
  { 

 

to

 

if (($_FILES["uploadFile"]["type"] == "image/gif") 
|| ($_FILES["uploadFile"]["type"] == "image/pjpeg")
|| ($_FILES["uploadFile"]["type"] == "image/tif")
|| ($_FILES["uploadFile"]["type"] == "image/png")
|| ($_FILES["uploadFile"]["type"] == "image/photoshop")
|| ($_FILES["uploadFile"]["type"] == "image/bmp")) 
|| ($_FILES["uploadFile"]["type"] == "image/pjpeg")) 
  { 

Just having a look at this again this morning, and added in a

 

phpinfo ();

 

Which is correctly listing the max file upload size as 8M, so I'm pretty stuck now.

 

It's still bringing up my 'Please select a valid image file type. The library supports .jpg, .gif, and .png files.'

 

So it's not OK for jpgs >2M, even tho' the max file size is set to 8M, and it is fine for jpgs < 2M.

 

Any more ideas.....?

OK - tried that with a file > 2MB, and got the output :

 

Array ( [name] => DSC00023.JPG [type] => [tmp_name] => [error] => 1 => 0 )

 

Tried it with a file <2MB, and got the output :

 

Array ( [name] => A8DTRE.jpg [type] => image/pjpeg [tmp_name] => c:/wamp/tmp\php28D0.tmp [error] => 0 => 39168 )

 

So in the first one, for some reason it didn't seem to recognise the file type, as the 'image/pjpeg' was missing?

 

Just spotted that the

 

upload_max_filesize is still showing as 2M in phpinfo(), even tho' I've changed it to 8M in the php.ini file, and added

 

<?php
ini_set('upload_max_filesize', '8M'); 
?>

 

to the top of the page with the upload script.

 

I changed the post_max_size to 9M in the php.ini, but it's still showing as 8M in the phpinfo() too.

 

What could be stopping this from taking effect, if it's changed in the php.ini file, and forced using ini_set?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.