Yury Merezhkov
asked on
File Upload Issue
Hi guys,
I have this script to upload a file:
<?php
$target_path = "uploads/";
$target = $target_path.basename($_FI LES['image path']['na me']);
move_uploaded_file($_FILES ['imagepat h']['tmp_n ame'], $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.
I have this script to upload a file:
<?php
$target_path = "uploads/";
$target = $target_path.basename($_FI
move_uploaded_file($_FILES
?>
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
upload.php
--------------------
<form enctype="multipart/form-da ta" 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']['n ame']);
if(move_uploaded_file($_FI LES['uploa dedfile'][ 'tmp_name' ], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['n ame']).
" 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
--------------------
<form enctype="multipart/form-da
<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']['n
if(move_uploaded_file($_FI
echo "The file ". basename( $_FILES['uploadedfile']['n
" 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
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'.
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'.
ASKER
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.
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.