Forum Moderators: coopster

Message Too Old, No Replies

File Upload Issues

         

huperphuff

12:15 am on Nov 18, 2008 (gmt 0)

10+ Year Member



Alright so I'm aware of how to upload files. I was using a small code (2 files) one of course with the form...and the second a php file to process the files.

First I tried uploading a small picture to the same directory where the files were stored...

I tried to set the folder's permissions to 777...however the php file in the directory would not run while the folder was writable. I'm guessing that is a server-side security feature although I'm not sure why that would be forbidden.

So second I moved the php files out of the directory and tried to get the files to upload to a writable directory.

I did some tests to see where it gets hung up. and when the processing php file runs it does not pick up the $_FILES variable at all...

I used print_r($_FILES); and the array was empty.

I checked the php.ini and the variables I expected to be set seemed okay...

Directive // Local Value // Master Value
file_uploads // On // On
upload_max_filesize // 2M // 2M
upload_tmp_dir // no value // no value

Any ideas?

willis1480

12:41 am on Nov 18, 2008 (gmt 0)

10+ Year Member



sorry without the code, couldnt begin to help. You got the permissions, then you should be good. $_FILES should give you all the posted files. make sure your form is setup correctly for posting the files.

otherwise please put your HTML page(for browsing to the file) and your php page for processing.

PS how did you chmod? make sure it did work as you think. manytimes, wether using cpanel, filezilla, etc... the chmod error is not easily seen and did not take place.

huperphuff

12:47 am on Nov 18, 2008 (gmt 0)

10+ Year Member



I'm under the impression that it doesn't require anything other than this:

HTML FILE:
<FORM ACTION="upload.php" METHOD="POST">
Upload this file:
<INPUT NAME="file_up" TYPE="file">
<INPUT TYPE="submit" VALUE="Send File">
</FORM>

PHP FILE:
echo $_FILES['file_up']['name'];
$file_name=$_FILES['file_up']['name'];
$add=$file_name; // the path with the file name where the file will be stored, upload is the directory name.
if(move_uploaded_file ($_FILES['file_up']['tmp_name'], $add)){
// do your coding here to give a thanks message or any other thing.
}else{
echo "Failed to upload file Contact Site admin to fix the problem";
}

echo("-".$_FILES['file_up']['size']."-<BR><BR><BR>");
print_r($_FILES);

huperphuff

12:54 am on Nov 18, 2008 (gmt 0)

10+ Year Member



and yes the php file is named upload.php

It does submit to the upload file because that's where the browser goes...but the upload file is not able to grab the submission data...meaning the form is messed up or the server is blocking something...

willis1480

1:01 am on Nov 18, 2008 (gmt 0)

10+ Year Member



in the form tag add:
enctype="multipart/form-data"

I think you need that. PHP code looks like should work.

huperphuff

1:07 am on Nov 18, 2008 (gmt 0)

10+ Year Member



You know...I saw that in another version...and half the time people just add extra crap...but you can't argue with results...it looks like it's working...

Thanks man

willis1480

1:10 am on Nov 18, 2008 (gmt 0)

10+ Year Member



um...that is key...it tells the server the mime type of the POST. without it, the server will just parse as $_POST and that just wont cut it for a file. Good to hear it is working.