Uploader Script Error

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
goodmangroup
-


Joined: 17 Aug 2011
Posts: 1

PostPosted: Wed Aug 17, 2011 7:37 am    Post subject: Uploader Script Error Reply with quote

Hi,
Hi, i am receving this error "Sorry, there was a problem uploading your file." when trying to upload any document type to our webserver.
Client Website: http://www.lisadaviesandassociates.com.au/test/file_upload.html

HTML CODE:
<html>
<head>
<title>PHP File Upload Example</title>
</head>
<form method="POST" enctype="multipart/form-data" action="./upload.php">
<label for="file">Select a file:</label> <input type="file" name="userfile" value=""><br />
<button type="submit">Upload File</button>
</form>
</body>
</html>

PHP CODE:
<?php
$target = "./test/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) ;
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
?>

Any help would be much appreciated.

Thanks
_________________
Rory Carter
Goodman Group Pty Ltd
Back to top View user's profile Send private message Send e-mail
admin
Site Admin


Joined: 03 Mar 2002
Posts: 772

PostPosted: Fri Aug 19, 2011 3:30 pm    Post subject: Re: Uploader Script Error Reply with quote

goodmangroup,

Your HTML file should also use uploaded as the variable name instead of userfile as in :

Code:
<input type="file" name="uploaded" value="">



From a quick look to the code there is also an error :

Code:

echo "The file ". basename( $_FILES['uploaded']['name']). " has been uploaded";


should be:

Code:

echo "The file ". basename( $_FILES['uploaded']['name']). " has been uploaded";


Your script requires that you create a subdirectory called "test" inside the directory where that .php script is. This is the main reason for the failure of that script that we can spot.

But the best is to let the script report the error code for the failure by changing the line :

Code:
echo "Sorry, there was a problem uploading your file.";


into :

Code:
echo "Sorry, there was a problem uploading your file - error code = ." .  $_FILES['uploaded']['error'] ;


The reported numeric value should be checked in <http://www.php.net/manual/en/features.file-upload.errors.php> where the error values are explained.
_________________
Forum Administrator
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group