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="upload.php" METHOD=POST ENCTYPE="multipart/form-data" name="upload" id="upload">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="65000">
Send this file:
<input type="file" name="userfile">
<INPUT TYPE="submit" VALUE="Upload file">
</FORM>
handler is
<?
if (is_uploaded_file($userfile)) {
copy($userfile, $HTTP_POST_FILES['userfile']['name']);
} else {
echo "error. File: '$userfile'.";
}
$filename=$HTTP_POST_FILES['userfile']['name'];
$fd = fopen ($filename, "r"
;
$contents = fread ($fd, filesize($filename));
fclose($fd);
$escaped_contents=mysql_escape_string($contents);
// Connecting, selecting database
$link = mysql_connect(""
;
mysql_select_db("",$db);
// Performing SQL query; assuming that the "picture" is a BLOB field
$query = "UPDATE studentpart SET pic='$escaped_contents' WHERE loginname='lulu'";
$result = mysql_query($query)
or die("Query failed"
;
// 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
Please help asap.
Thanks!
This is the code I used
<FORM ACTION="upload.php" METHOD=POST ENCTYPE="multipart/form-data" name="upload" id="upload">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="65000">
Send this file:
<input type="file" name="userfile">
<INPUT TYPE="submit" VALUE="Upload file">
</FORM>
handler is
<?
if (is_uploaded_file($userfile)) {
copy($userfile, $HTTP_POST_FILES['userfile']['name']);
} else {
echo "error. File: '$userfile'.";
}
$filename=$HTTP_POST_FILES['userfile']['name'];
$fd = fopen ($filename, "r"

$contents = fread ($fd, filesize($filename));
fclose($fd);
$escaped_contents=mysql_escape_string($contents);
// Connecting, selecting database
$link = mysql_connect(""

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

// 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