By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

file upload not showing up in /tmp linux

P: n/a
Jim
I'm having huge problems with a web server not putting the uploaded
file in the /tmp

here is my code can some one please point me in the right
direction?I'm thinking i've
done something with wrong with apache but can't find out what.

---- up.html ----
<HTML><BODY>
<FORM method="POST" enctype="multipart/form-data" action="./up.php">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000000">
<input type=file name=fupload>
<INPUT type="submit">
</FORM>
</BODY>
</HTML>
---- up.html ----
---- up.php ----
<HTML><BODY>
<?php
echo "main hi $fupload<BR>";
if( isset($fupload)){
echo "isset found hi $fupload_name<BR>";
}
?>
</BODY>
</HTML>
---- up.html ----
---- output from a file uploaded of 120k----

<HTML><BODY>
main hi <BR></BODY>
</HTML>
---- output ----
Jul 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Jim,

How PHP handle's uploaded files is quite different to normal variable
submission (which isn't mentioned in the PHP documentation very well).

$fupload won't be a variable containing the contents of the file you've
uploaded, but an array of file information in the global $_FILES array
(I donít code PHP with global variables on).

So for:

<FORM method="POST" enctype="multipart/form-data" action="./up.php">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000000">
<input type="file" name="fupload">
<INPUT type="submit">
</form>

To check if a person has selected a file, and submitted, then print the
file contents out, you would require the following PHP (for example).

<?php

//
// Check if a file has attached ('none' needed for IE compatability)
//
if ( (!empty($_FILES['fupload']['tmp_name']) ) &&
$_FILES['fupload']['tmp_name'] != 'none' )
{

$file_content = addslashes(fread(fopen($_FILES['fupload']['tmp_name'],
'r'), filesize($_FILES['fupload']['tmp_name']) )); // Read File

echo $file_content; // Echo it

}
else
{
echo 'No file was submitted';
}

?>

Btw, $_FILES['fupload']['tmp_name'] returns the name/path of the file as
it's temporarily stored on the servers FS, so having a

echo $_FILES['fupload']['tmp_name'];

would return something like

/tmp/php8329x9

Ovbiously in the $_FILES['fupload'], the 'fupload' corresponds to the
name of the form file bit in your form, so you could have multiple
uploads on the one form with $_FILES['fuploadwhatever'],
$_FILES['fupload3'] etc.. corresponding to a:

<input type="file" name="fupload3">
<input type="file" name="fuploadwhatever">
Hope this helps.
Grant
Jim wrote:
I'm having huge problems with a web server not putting the uploaded
file in the /tmp

here is my code can some one please point me in the right
direction?I'm thinking i've
done something with wrong with apache but can't find out what.

---- up.html ----
<HTML><BODY>
<FORM method="POST" enctype="multipart/form-data" action="./up.php">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000000">
<input type=file name=fupload>
<INPUT type="submit">
</FORM>
</BODY>
</HTML>
---- up.html ----
---- up.php ----
<HTML><BODY>
<?php
echo "main hi $fupload<BR>";
if( isset($fupload)){
echo "isset found hi $fupload_name<BR>";
}
?>
</BODY>
</HTML>
---- up.html ----
---- output from a file uploaded of 120k----

<HTML><BODY>
main hi <BR></BODY>
</HTML>
---- output ----


Jul 16 '05 #2

P: n/a
Jim
Absolutly Awesome thanks a ton.
Jul 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.