Solved

File Upload Issue

Posted on 2007-03-21
6
225 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

724 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