PHP Form Upload Troubles.

PHP Form Upload Troubles.

Posted by: akmattb
Posted on: 2007-02-08 00:08:00

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:
<more form above>
<td colspan="3">
Please choose a file: <input name="uploadedfile" type="file" />
</td>
<more form below>

here is my php code that handles the upload:
<more php above>
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);
}
<more php below>

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

Re: PHP Form Upload Troubles.

Posted by: nathan823
Posted on: 2007-02-08 01:12:00

try this

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

and what is the error message?

Re: PHP Form Upload Troubles.

Posted by: akmattb
Posted on: 2007-02-08 09:22:00

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.

Re: PHP Form Upload Troubles.

Posted by: silkrooster
Posted on: 2007-02-08 16:14:00

Is it possible that it will never run because

if(isset($_POST['uploaded']))

should be

if(isset($_POST['uploadedfile']))

Silk

My website

Re: PHP Form Upload Troubles.

Posted by: akmattb
Posted on: 2007-02-08 16:28:00

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

HTML FORM
Please choose a file: <input name="uploadedfile" type="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);

Re: PHP Form Upload Troubles.

Posted by: nathan823
Posted on: 2007-02-08 16:59:00

sample form
<form

Re: PHP Form Upload Troubles.

Posted by: akmattb
Posted on: 2007-02-08 17:17:00

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
<input type="submit" value="Send File">
and in mine i have
<input type="submit" name="new_submit" value="Submit" />

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



Re: PHP Form Upload Troubles.

Posted by: nathan823
Posted on: 2007-02-08 18:38:00

In reply to:

[error] => 2


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

Re: PHP Form Upload Troubles.

Posted by: akmattb
Posted on: 2007-02-08 21:11:00

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 <form> tag. you did... Therefore ... yours worked and mine didn't. I added it to mine and it uploaded just fine.

Thanks,
Matt

Tags: file uploadsphp formupload scripti don t carephp file