Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File upload problems...

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi. i seem to be having a problem running this script locally. I just installed "Nu Sphere" on my computer, and am having a go at programming PHP. The problem i am having is that $uploadfile_name, $uploadfile_size and $uploadfile_type do not seem to be getting passed through :(

The code i am using is;

Code:
<?php


echo $uploadfile_name;

if (!$uploadfile) { show_html(); } else { sendmain($uploadfile, $uploadfile_name, $uploadfile_size); }

function show_html() {

?>

<FORM METHOD=GET ACTION=&quot;attach.php&quot; ENCTYPE=&quot;multipart/form-data&quot;>
<INPUT type=&quot;FILE&quot; name=&quot;uploadfile&quot;>

<INPUT TYPE=&quot;submit&quot; Value=&quot;send file&quot;>

</FORM>

<?

} // end the show html part


function sendmain($uploadfile_1, $uploadfile_2, $uploadfile_3) {

echo &quot;The name and path of file is $uploadfile_1<BR>&quot;;
echo &quot;The name and path of file is $uploadfile_2 <BR>&quot;;
echo &quot;The size of file is $uploadfile_3 <BR>&quot;;

}


function error($error) {
echo $error;
exit;
}  // end the error sub



?>

The result is;

Code:
The name and path of file is C:\\ha.txt
The name and path of file is 
The size of file is

Anyone got any ideas?

Thanks

Andy
 
For starters you have to define the maxfile size in the html. For the rest the file is uploaded to a temp filename, therefor you need to copy the file to the right location.
You can find more information in de handeling file uploads part of php.net:
mcvdmvs
-- &quot;It never hurts to help&quot; -- Eek the Cat
 
Still having problems :(

I followed their example at the URL you provided, but it still wont work. I am using the following code;

Code:
<?php


if (!$uploadfile) { show_html(); } else { sendmain($uploadfile, $uploadfile_name, $uploadfile_size, $uploadfile_type); }

function show_html() {

?>

<form enctype=&quot;multipart/form-data&quot; action=&quot;attach.php&quot; method=&quot;post&quot;>
<input type=&quot;hidden&quot; name=&quot;MAX_FILE_SIZE&quot; value=&quot;1000&quot;>
Send this file: <input name=&quot;uploadfile&quot; type=&quot;file&quot;>
<input type=&quot;submit&quot; value=&quot;Send File&quot;>
</form>



<?

} // end the show html part


function sendmain($uploadfile_1, $uploadfile_2, $uploadfile_3, $uploadfile_4) {



echo &quot;The name and path of file is $uploadfile_1<BR>&quot;;
echo &quot;The name and path of file is $uploadfile_2 <BR>&quot;;
echo &quot;The size of file is $uploadfile_3 <BR>&quot;;
echo &quot;The size of file is $uploadfile_4 <BR>&quot;;

// copy($uploadfile_1, &quot;&quot;);


}


function error($error) {
echo $error;
exit;
}  // end the error sub



?>

The result I get is;

Code:
The name and path of file is none
The name and path of file is pamanual.pdf 
The size of file is 0 
The size of file is application/pdf

As you can see the file size is being returned as 0, and then files path is being set as 'none' :( The weird thing though is that the other stuff is being set ok (the _type and _name).

If I change the form method to GET it just seems to send the file address, but nothing else is registered :(

Anyone???

Thanks

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top