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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Upload file could not recognize file

Status
Not open for further replies.

namida

Programmer
Joined
May 29, 2003
Messages
101
Location
AU
I tried to use several examples and all give errors like not valid stream source or no such file. I think it does not recognize the field userfile into $userfile. Because even when it's supposed to echo Error $userfile but it just print Error ''.

Please help asap.
Thanks!

This is the code I used

<FORM ACTION=&quot;upload.php&quot; METHOD=POST ENCTYPE=&quot;multipart/form-data&quot; name=&quot;upload&quot; id=&quot;upload&quot;>
<INPUT TYPE=&quot;hidden&quot; name=&quot;MAX_FILE_SIZE&quot; value=&quot;65000&quot;>
Send this file:
<input type=&quot;file&quot; name=&quot;userfile&quot;>
<INPUT TYPE=&quot;submit&quot; VALUE=&quot;Upload file&quot;>
</FORM>

handler is

<?

if (is_uploaded_file($userfile)) {
copy($userfile, $HTTP_POST_FILES['userfile']['name']);
} else {
echo &quot;error. File: '$userfile'.&quot;;
}

$filename=$HTTP_POST_FILES['userfile']['name'];

$fd = fopen ($filename, &quot;r&quot;);
$contents = fread ($fd, filesize($filename));
fclose($fd);

$escaped_contents=mysql_escape_string($contents);

// Connecting, selecting database
$link = mysql_connect(&quot;&quot;);
mysql_select_db(&quot;&quot;,$db);

// Performing SQL query; assuming that the &quot;picture&quot; is a BLOB field
$query = &quot;UPDATE studentpart SET pic='$escaped_contents' WHERE loginname='lulu'&quot;;
$result = mysql_query($query)
or die(&quot;Query failed&quot;);

// Closing connection
mysql_close($link);

?>


error is .

File: ''.
Warning: fopen(joeylim.jpg) [function.fopen]: failed to create stream: No such file or directory in /home/bus8646/ on line 11

Warning: filesize() [function.filesize]: Stat failed for joeylim.jpg (errno=2 - No such file or directory) in /home/bus8646/ on line 12

Warning: fread(): supplied argument is not a valid stream resource in /home/bus8646/ on line 12

Warning: fclose(): supplied argument is not a valid stream resource in /home/bus8646/ on line 13

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/bus8646/ on line 19
Query failed
 
I Tried using if($userfile) in another code that I got from earlier posts in this forum
IT always echoes &quot;No File&quot;
like

<?php
if ($userfile==&quot;&quot;) {
echo &quot;No File&quot;;
} else {
$upload_file = $_FILES['location']['name'];
$temp = $_FILES['location']['tmp_name'];
$extension = substr($upload_file,-4);

$image = &quot;images/1&quot;.$extension;
move_uploaded_file($temp, $image);
echo 'Successfully added';
}




?>
 
I don't know.
I thought it was the same with textboxes and everything else?
Usually what I do is just name the textbox /whatever with say name and then submit it to a handler file
and then the handler file will recognize it automatically as $name

It works but is it different with file?

sorry I'm slow
 
Alright thanks
The register_globals is on
but the $_POST and $HTTP_POST_VARS only displays Array ( [MAX_FILE_SIZE] => 65000 ) Array ( [MAX_FILE_SIZE] => 65000 )

what should I do now?
 
I mean how do I make the File type input recognized..?

thx
 
hi,

There is no difference in input file type and other form types as far as retrieving the variabbles is concerned.

If u can get other variable by $formtextfieldname, then u shd also get the input file type varibale.

try printing the actual name of the file on ur Hard Disk by echoing '$userfile_name' and see if u can get it..

Spookie

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
$userfile_name shows up as joeylim.jpg
but when I do the print_r($HTTP_POST_VARS);
the userfile is not there..

thx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top