?
Solved

File Upload Issue

Posted on 2007-03-21
6
Medium Priority
?
227 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:Yury Merezhkov
[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 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 7

Author Comment

by:Yury Merezhkov
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:Yury Merezhkov
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.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

762 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