Re: File input from form not detected
| From: | Dewi Wahyuni | Date: | Sat, 31 May 2003 15:48:58 +0000 |
| Subject: | Re: File input from form not detected | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-28193@lists.php.net to get a copy of this message | ||
Hi everyone thanks.
I did add the enctype but it's still not working. Here're
the codes
Sorry if I posted to the wrong list. because I was trying to store the file as well in the mysql db
blob. Someone suggested to print all the $ post vars as I print, only the MAX_FILE_SIZE shows up as
a variable. I also tried directy assigning $userfile = "C: blabla" and it gives the same
thing
One more thing do I have to use base_64 encode for this ?
upload.html
-----------
<html>
<body>
<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>
</body>
</html>
upload.php
----------
<?
phpinfo();
echo $_POST['userfile']['tmp']; // never got echoed it seems to be empty.
if (is_uploaded_file($userfile))
copy($userfile, $HTTP_POST_FILES['userfile']['name']);
else echo "error. File: $userfile."; // this is invoked but it can't print
$userfile either.
$filename=$HTTP_POST_FILES['userfile']['name'];
$fd = fopen ($filename, "rb");
$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);
?>
errors example filename tried to upload is c:\\windows\Backgrnd.gif
------------
error. File: .
Warning: fopen(Backgrnd.gif) [function.fopen]: failed to create stream: No such file or directory in
/home/bus8646/www/tryout/upload.php on line 9
Warning: filesize() [function.filesize]: Stat failed for Backgrnd.gif (errno=2 - No such file or
directory) in /home/bus8646/www/tryout/upload.php on line 10
Warning: fread(): supplied argument is not a valid stream resource in
/home/bus8646/www/tryout/upload.php on line 10
Warning: fclose(): supplied argument is not a valid stream resource in
/home/bus8646/www/tryout/upload.php on line 11
Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in
/home/bus8646/www/tryout/upload.php on line 15
Query failed
____________________________________________________________
Get advanced SPAM filtering on Webmail or POP Mail ... Get Lycos Mail!
http://login.mail.lycos.com/r/referral?aid=27005