Link to home
Start Free TrialLog in
Avatar of Yury Merezhkov
Yury MerezhkovFlag for United States of America

asked on

File Upload Issue

Hi guys,

I have this script to upload a file:

<?php
      $target_path = "uploads/";

      $target = $target_path.basename($_FILES['imagepath']['name']);
      move_uploaded_file($_FILES['imagepath']['tmp_name'], $target);
?>

It works fine with a file like WeddingPhoto.jpg, but it doesn't work with a file like DSC_0480pp.jpg. Why can that be? Thanks.
ASKER CERTIFIED SOLUTION
Avatar of glcummins
glcummins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of exoska
exoska

well if it worked for one, other should work . i d tried on 2 different servers.
2 reasons are possible

first , and most probably file size is too big for the upload ( it is set and can be changed from php.ini of the server, just create a info.php and put this <?php phpinfo(); ?> and check the upload limit ..

second you might already have uploaded some file with the same name. and it cant overwrite it for security reasons.


upload.php
--------------------
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

Uploader.php
-----------------
<?
$target_path = "images/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']).
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}
?>

Please check this code with your files and let me know

Regards,
M.Raja
Avatar of Yury Merezhkov

ASKER

It gives me no error, but the file doesn't get uploaded. DSC_0480pp.jpg is 2.5 Mb, while WeddingPhoto.jpg is about 500 Kb. Can it be happening because of the large size?
I see that you added some error reporting. When you originally posted, was the script failing silently, or was a PHP error being produced?

What is the upload size limit in the php.ini file? I see that you have a MAX_FILE_SIZE specified in your form, but that does not override any maximum value set in php.ini. Specifically, we need to know the value of 'upload_max_filesize = ', and the size of 'DSC_0480pp.jpg'.
Oh I know what the issue was. I changed upload_max_filesize in php.ini to 10M and everything works now. glcummins, thanks for mentioning the size issue. glcummins gets the points since he was first to mention the size.