Page 1 of 1

File Upload Wont work

Posted: Thu May 18, 2006 9:39 pm
by maverickbce8
i am a newbie with php and html......i really need a file upload button on my website and the instructions on how to make it work. I have found many that give the html code for the forum and the php that runs it, but none of the tutorials give enough detailed description on where to save the php and html to make them work together etc.

Please Help!!
-Brian

Posted: Thu May 18, 2006 9:41 pm
by Benjamin

Code: Select all

<form enctype="multipart/form-data" action="_URL_" method="post">
 <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
 Send this file: <input name="userfile" type="file" />
 <input type="submit" value="Send File" />
</form>

Code: Select all

<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . $_FILES['userfile']['name'];

print "<pre>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    print "File is valid, and was successfully uploaded. ";
    print "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);
}
print "</pre>";

?>

Posted: Thu May 18, 2006 9:46 pm
by maverickbce8
ok but what do i do with that php code?

Posted: Thu May 18, 2006 9:47 pm
by s.dot
stick that & the form in your text editor, save as upload.php (or whatever you want), and then upload that page to a php enabled webserver. =]

Posted: Thu May 18, 2006 9:49 pm
by Benjamin
Put this in a file named upload.php

Code: Select all

<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . $_FILES['userfile']['name'];

print "<pre>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    print "File is valid, and was successfully uploaded. ";
    print "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);
}
print "</pre>";

?>

<form enctype="multipart/form-data" action="_URL_" method="post">
 <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
 Send this file: <input name="userfile" type="file" />
 <input type="submit" value="Send File" />
</form>
And then read the PHP manual. Available in my signature below.

Change $uploaddir = '/var/www/uploads/'; to the folder you want the pictures to go. Make sure it's permissions are set to 0777.

Posted: Thu May 18, 2006 9:51 pm
by maverickbce8
ok ill give it a try.....thanks alot