Subject: Fread, fopen, problem with local file not recognized
| From: | Dewi Wahyuni | Date: | Thu, 29 May 2003 05:11:59 +0000 |
| Subject: | Subject: Fread, fopen, problem with local file not recognized | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-28142@lists.php.net to get a copy of this message | ||
I am trying a script to upload an image
the problem is the php does not recognize it as a local file
The error I get is :
error. File: ''.
Warning: fopen(joey lim.jpg) [function.fopen]: failed to create stream: No such file or directory in
/home/bus8646/www/tryout/upload.php on line 11
Warning: filesize() [function.filesize]: Stat failed for joey lim.jpg (errno=2 - No such file or
directory) in /home/bus8646/www/tryout/upload.php on line 12
Warning: fread(): supplied argument is not a valid stream resource in
/home/bus8646/www/tryout/upload.php on line 12
Warning: fclose(): supplied argument is not a valid stream resource in
/home/bus8646/www/tryout/upload.php on line 13
Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in
/home/bus8646/www/tryout/upload.php on line 19
Query failed
Example code :
<?
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("localhost", "*****","******");
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);
?>
Basically the file is not recognize as local, i have no idea why, the file I sent was C:\\ based
This is another code that I have tried
<?
$userfile = "C:\\joey lim.jpg";
$UPLOAD = fopen( $userfile, "r" );
$contents = fread( $UPLOAD,filesize($userfile));
fclose( $UPLOAD );
$SAVEFILE = fopen("upload//".$userfile_name, "wb" );
fwrite( $SAVEFILE, $contents,$userfile_size);
fclose( $SAVEFILE );
echo "Server HaD Receive the Upload Files!";
?>
Warning: fopen(C:\joey lim.jpg) [function.fopen]: failed to create stream: No such file or directory
in /home/bus8646/www/tryout/upload2.php on line 3
Warning: filesize() [function.filesize]: Stat failed for C:\joey lim.jpg (errno=2 - No such file or
directory) in /home/bus8646/www/tryout/upload2.php on line 4
Warning: fread(): supplied argument is not a valid stream resource in
/home/bus8646/www/tryout/upload2.php on line 4
Warning: fclose(): supplied argument is not a valid stream resource in
/home/bus8646/www/tryout/upload2.php on line 5
Warning: fopen(upload//) [function.fopen]: failed to create stream: Is a directory in
/home/bus8646/www/tryout/upload2.php on line 6
Warning: fwrite(): supplied argument is not a valid stream resource in
/home/bus8646/www/tryout/upload2.php on line 7
Warning: fclose(): supplied argument is not a valid stream resource in
/home/bus8646/www/tryout/upload2.php on line 8
Server HaD Receive the Upload Files!
Can someone please help
Dewi
____________________________________________________________
Get advanced SPAM filtering on Webmail or POP Mail ... Get Lycos Mail!
http://login.mail.lycos.com/r/referral?aid=27005