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
Solved

File Upload Issue

Posted on 2007-03-21
6
222 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP not parsing ' character 12 46
how to use Initialization Vector for openssl_encrypt() 5 58
php help 34 58
SQL querys that gives me from one table into another. 2 24
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

840 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