Page 1 of 1

what's wrong uploading a file

Posted: Sat Mar 13, 2004 4:35 am
by gamer
whats wrong i upload a file and if i check the dir there's no file
code html

Code: Select all

<form enctype="multipart/form-data" action="/upload/add.php" method="post">
 <input type="hidden" name="MAX_FILE_SIZE" value="99999999999">
  Upload dit bestand: <input name="userfile" type="file">
   <input type="submit" value="Upload!">
    </form>
my php code

Code: Select all

<?php
/*
test file for uploading files
(C)opyright stefan feenstra
*/
// Voor PHP 4.1.0 moet $HTTP_POST_FILES gebruikt worden in plaats van $_FILES.
if (is_uploaded_file($_FILES&#1111;'userfile']&#1111;'tmp_name'])) &#123;
copy($_FILES&#1111;'userfile']&#1111;'tmp_name'], "c:/website/upload/files/");
&#125; else &#123;
echo "Mogelijke aanval gespot: " . $_FILES&#1111;'userfile']&#1111;'name'];
&#125;
/* ...of... */
move_uploaded_file($_FILES&#1111;'userfile']&#1111;'tmp_name'], "c:/website/upload/files");
?>
EDIT: code was from php manual

Posted: Sat Mar 13, 2004 6:13 am
by Pointybeard
Could be an apache httpd.conf problem. What dir is your script in? try changing the upload path c:/website/upload/files/ to the dir you have your script in. See if that works. Also, try

Code: Select all

print "<pre>";
print_r($_FILES);
print "</pre>";
to make sure that the data is actually there to start with.

Actually, try this out

Code: Select all

<?php
// In PHP earlier then 4.1.0, $HTTP_POST_FILES should be used instead of $_FILES.
// In PHP earlier then 4.0.3, use copy() and is_uploaded_file() instead of move_uploaded_file

$uploaddir = 'c:/website/upload/files';

print "<pre>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $_FILES['userfile']['name'])) {
    print "File is valid, and was successfully uploaded.  Here's some more debugging info:\n";
    print_r($_FILES);
} else {
    print "Possible file upload attack!  Here's some debugging info:\n";
    print_r($_FILES);
}

?>
Thats outta the english manual, Give that a whirl.

-PB