Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Upload Problems

Status
Not open for further replies.

dolphin99

Programmer
Jan 18, 2004
12
AU
Hi,
I am fairly new to PHP, I am using the script below to try to upload a file to my server but get Could not upload error messages.
It look spretty straight forward, any ideas what coul dbe wrong...?

Thanks.

<?php
if ($img1_name != "") {
@copy("$img1" , "/home/admin/ or die("Couldn't Upload Your File.");
} else {
die("No File Specified");
}
?>

----------------------------------------------

<HTML>
<HEAD>
<TITLE>File Upload Successful</TITLE>
</HEAD>
<BODY>

<H1>File Upload Successful!</H1>
<P>Successfully Sent: <?php echo "$img1_name"; ?> , a <?php echo "$img1_size"; ?> byte file with the extension type of <?php echo "$img1_type"; ?> </P>

</BODY>
</HTML>
 
As a beginner myself I'm not familiar with this @copy function or how it works, so I can't help with the scripting.
I do know however,that to upload files to a server using php the php settings on the server have to allow access to a temporary upload directory, or else the upload will fail.
You can find the list of php configuration settings of the server by passing the function phpinfo(). From the long list of information that this gives you need look for upload_tmp_dir and make sure that it is set to a directory. If it says 'no value' then this could well be the problem. I asked my web host if he could set this configuration on his server and he refused. Apparently it's often mis-used. Also check that php is not running in 'safe mode'. You will also get this info from phpinfo().
On the other hand it may simply be that there's something wrong with the script.
Hope this helps.
 
dolphin99:
I recommend also that you read the PHP online manual section titled "Handling File Uploads"



Also, I strongly recommend that you never use the "@" error-supression operator. All it does it prevent the display of error messages. As it does so, it nearly guarantees that your code is not goint to handle errors gracefully.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top