PHP Form Upload Troubles


#1

I am fairly new to php file uploads. but at this moment i am just trying to make a simple upload script that will throw a file into a directory. i don’t care what the file is as long as its in the directory.
The form itself works fine. Just the upload doesn’t happen.

here is my html form code:

Please choose a file:

here is my php code that handles the upload:

if(isset($_POST[‘uploaded’])) {
// Where the file is going to be placed
$target_path = “uploads/”;

/* Add the original filename to our target path.
Result is “uploads/filename.extension” */
$target_path = $target_path . basename( $_FILES[‘uploadedfile’][‘name’]);
move_uploaded_file($_FILES[‘userfile’][‘tmp_name’], $uploadfile);
}

Any help would be greatly appreciated! Thanks!!!
Matt


#2

try this

$target_path =getcwd()."/uploads/";

and what is the error message?

Save [color=#CC0000]$97[/color] (max discount) on dreamhost plans by using promo code: [color=#CC0000]97CRAZY[/color].


#3

hey thanks for the input, but my problem still occurs. here is my updated code with your information:

if(isset($_POST[‘uploaded’])) {
// Where the file is going to be placed
$target_path =getcwd()."/uploads/";

/* Add the original filename to our target path.
Result is “uploads/filename.extension” */
$target_path = $target_path . basename( $_FILES[‘uploadedfile’][‘name’]);
move_uploaded_file($_FILES[‘userfile’][‘tmp_name’], $uploadfile);
}

As far as the error message goes. Its just that nothing happens. I have tested several pre-made scripts that have a very simple form of error checking but none let me know like what the error is… so it basically only tells me if it doesn’t work.


#4

Is it possible that it will never run because

if(isset($_POST[‘uploaded’]))

should be

if(isset($_POST[‘uploadedfile’]))

Silk

My website


#5

Hmm again not working… and just for kicks i took out the isset check.

HTML FORM
Please choose a file:

PHP CODE
// Where the file is going to be placed
$target_path =getcwd()."/uploads/";

/* Add the original filename to our target path.
Result is “uploads/filename.extension” */
$target_path = $target_path . basename( $_FILES[‘uploadedfile’][‘name’]);
move_uploaded_file($_FILES[‘userfile’][‘tmp_name’], $uploadfile);


#6

[color=#0000CC]sample form[/color]

Send this file:

[color=#0000CC]sample upload[/color]
$uploaddir = getcwd().’/uploads/’;
$uploadfile = $uploaddir. $_FILES[‘userfile’][‘name’];

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);
}

what error message do you see after you upload a file?

Save [color=#CC0000]$97[/color] (max discount) on dreamhost plans by using promo code: [color=#CC0000]97CRAZY[/color].


#7

Well thats the thing ive been trying to say is that there is no error message…

I tried again 2 times… first by putting your code in my pages. I had to change the here was the result…:

Possible file upload attack! Here’s some debugging info: Array ( )

Here is the result of putting the code into blank pages:
Possible file upload attack! Here’s some debugging info: Array ( [userfile] => Array ( [name] => map_of_the_internet.jpg [type] => [tmp_name] => [error] => 2 [size] => 0 ) )

The directory /uploads/ was left empty after both tries.

And the only thing that i can think that would be different is the submit button value… in your example you have

and in mine i have

Thanks for all your guy’s help. I really do appreciate this!!
Matt


#8

Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form.

To solve the problem, modify the hidden field

if i’m not wrong, 30000 is 30000 bits. So it is very small. Try to increase the MAX_FILE_SIZE value

Save [color=#CC0000]$97[/color] (max discount) on dreamhost plans by using promo code: [color=#CC0000]97CRAZY[/color].


#9

haha ok it works… Your version does (after i expanded the maximum file size.)…

File is valid, and was successfully uploaded. Here’s some more debugging info: Array ( [userfile] => Array ( [name] => CCNA2_CS1_en.pdf [type] => application/pdf [tmp_name] => /tmp/phpr1DPWL [error] => 0 [size] => 333482 ) )

okokokokok… the problem was
"enctype=“multipart/form-data”"

I didn’t have this in my tag. you did… Therefore … yours worked and mine didn’t. I added it to mine and it uploaded just fine.

Thanks,
Matt