|
-
Oct 23rd, 2007, 10:18 AM
#1
Thread Starter
PowerPoster
[RESOLVED] Php File Upload
Ok I must have done this about 20 times in the past but for some reason I cant get my latest file upload to work?
Errors :
Code:
Possible file upload attack!
Here is some more debugging info:Array
(
[uploadedfile] => Array
(
[name] => aces.jpeg
[type] => image/jpeg
[tmp_name] => /home/identisysuk/public_html/tmp/phpFaqFr0
[error] => 0
[size] => 50985
)
)
And code -
PHP Code:
$uploaddir = '/home/identisysuk/public_html/uploads/';
$uploadfile = $uploaddir . "tempFile";
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}
echo 'Here is some more debugging info:';
print_r($_FILES);
//Print the error handle out here
print "</pre>";
The uploads directory has the correct permissions so that shouldn't be a problem! Any assistance? This has to be somthing daft, its just one of them days!
Thanks
-
Oct 23rd, 2007, 04:28 PM
#2
Re: Php File Upload
try taking away the last / on the uploaddir
PHP Code:
$uploaddir = '/home/identisysuk/public_html/uploads';
My usual boring signature: Something
-
Oct 24th, 2007, 03:10 AM
#3
Thread Starter
PowerPoster
Re: Php File Upload
Thanks but the issue still remains still producing the same error code of 0 :-/
Pino
-
Oct 24th, 2007, 07:04 AM
#4
Thread Starter
PowerPoster
Re: Php File Upload
I'm getting a little frustrated with this now, can anyone help?
-
Oct 24th, 2007, 04:24 PM
#5
Re: Php File Upload
Where is your script located?
If it is located in public_html then you just need the upload directory to be 'uploads'
My usual boring signature: Something
-
Oct 25th, 2007, 03:05 AM
#6
Thread Starter
PowerPoster
Re: Php File Upload
its actually in a sub folder off public_html (public_html/Admin)
-
Oct 25th, 2007, 04:30 PM
#7
Re: Php File Upload
then the upload directory should be
'../uploads'
My usual boring signature: Something
-
Oct 26th, 2007, 10:35 AM
#8
Re: Php File Upload
I don't think it's that. He has a / at the beginning so it will go to the root, then follow the path.
I reckon it's because your new filename has no extension therefore the move function will see the filename as a folder and break.
-
Nov 5th, 2007, 04:34 AM
#9
Thread Starter
PowerPoster
Re: Php File Upload
I'm not sure I follow, how would i add the extension on then?
Thanks
-
Nov 5th, 2007, 04:37 AM
#10
Re: Php File Upload
 Originally Posted by the182guy
I reckon it's because your new filename has no extension therefore the move function will see the filename as a folder and break.
Not true. File name extensions aren't required on either *nix or Windows.
-
Nov 5th, 2007, 04:39 AM
#11
Re: Php File Upload
Your debug output says 'uploadedfile' but in the code you're using $_FILES['userfile']. Change this to $_FILES['uploadedfile'].
-
Nov 5th, 2007, 04:44 AM
#12
Thread Starter
PowerPoster
Re: Php File Upload
Thanks Pengate, my code is below.
PHP Code:
//First do the file uploads
$target = "../uploads/";
$target = $target . basename( $_FILES['uploadedfile']['name']) ;
//If everything is ok we try to upload it
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target))
{
echo "The file ".
basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
no luck still. this should be one of the easiest things to do.
Thanks
Last edited by Pino; Nov 5th, 2007 at 04:50 AM.
-
Nov 5th, 2007, 04:47 AM
#13
Re: Php File Upload
What does the HTML for the file input control look like?
-
Nov 5th, 2007, 04:48 AM
#14
Thread Starter
PowerPoster
Re: Php File Upload
Thanks.
Code:
<form enctype='multipart/form-data' action='addProduct.php' method='POST'>
<input type='hidden' name='MAX_FILE_SIZE' value='100000' />
<input name='uploadedfile' type='file' />
</form>
-
Nov 5th, 2007, 05:05 AM
#15
Re: Php File Upload
Try this:
PHP Code:
define('UPLOAD_DIR', '../uploads/');
// attempt to move the file
if (isset($_FILES['uploadedfile']))
{
$target = UPLOAD_DIR . $_FILES['uploadedfile']['name'];
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target) === true)
{
echo 'Success: ' . $_FILES['uploadedfile']['name'] . ' uploaded.';
}
else
{
echo 'Failed to move file: ';
$errors = array(
UPLOAD_ERR_INI_SIZE => 'The uploaded file exceeds the upload_max_filesize directive in php.ini.',
UPLOAD_ERR_FORM_SIZE => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.',
UPLOAD_ERR_PARTIAL => 'The uploaded file was only partially uploaded.',
UPLOAD_ERR_NO_FILE => 'No file was uploaded.',
UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder.',
UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk.',
UPLOAD_ERR_EXTENSION => 'File upload stopped by extension.'
);
if (array_key_exists($err = $_FILES['uploadedfile']['error'], $errors))
echo $errors[$err];
else
echo 'Unknown error: ' . $err;
}
}
else
{
echo 'No file was uploaded.';
}
-
Nov 5th, 2007, 05:09 AM
#16
Thread Starter
PowerPoster
Re: Php File Upload
worked.....
Whats differant?
Thanks
-
Nov 5th, 2007, 05:15 AM
#17
Re: Php File Upload
Nothing that I can see. I don't know why yours didn't work. Perhaps you had a typo somewhere.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|