Solved

File Upload Issue

Posted on 2007-03-21
6
219 Views
Last Modified: 2008-02-20
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.
0
Comment
Question by:RealSnaD
6 Comments
 
LVL 24

Accepted Solution

by:
glcummins earned 500 total points
ID: 18766047
What is the error you encounter? Is there a chance that 'DSC_0480pp.jpg' is not getting uploaded (perhaps a size issue), and therefore the rest of the script fails?

Check to make sure that you can write to the target location, and that the temp file exists and is readable (is_readable($_FILES['imagepath']['tmp_name'])).
0
 
LVL 3

Expert Comment

by:exoska
ID: 18766069
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.


0
 
LVL 14

Expert Comment

by:raja_ind82
ID: 18766077
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
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 7

Author Comment

by:RealSnaD
ID: 18766086
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?
0
 
LVL 24

Expert Comment

by:glcummins
ID: 18766106
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'.
0
 
LVL 7

Author Comment

by:RealSnaD
ID: 18766163
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.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now