note 35629 deleted from features.file-upload by aidan
| From: | aidan@php.net | Date: | Thu, 05 Aug 2004 07:49:45 +0000 |
| Subject: | note 35629 deleted from features.file-upload by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-73984@lists.php.net to get a copy of this message | ||
Note Submitter: heivio@hotmail.com
----
To upload huge file to any BLOB to mySQL database, there is a simplest solution with only one
special requirement. You must have the right to use command
{LOAD_FILE("<FilePathname>")}. <FilePathname> must be composed with
'/' (forward slashes) or you may use 'str_replace(str,str,str)' to replace the
backward ('\') slashes for windows platform.
e.g.
C:\WINDOWS\TEMP\php2064.TMP (pathname backward slashes)
C:/WINDOWS/TEMP/php2064.TMP (pathname with forward slashes)
Example:
(Assume you have asscess right to "LOAD_FILE()" in mySQL)
<?php
//establish database connection using user defined class.
$db = new dbConnection();
$link = $db->connect();
$fileName = $_FILES['image']['tmp_name'];
$imgLocation = str_replace("\\","/", $fileName);
/* '\\' represent '\' */
echo $imgLocation;
$rval['update'] = mysql_query("UPDATE Users
SET photo = LOAD_FILE(\"$imgLocation\")
WHERE userid = 'foo' ",$link)
or
die (mysql_error($link));
//commit is used , just in case.
$commit = mysql_query('commit');
mysql_close($link);
?>