Forum Moderators: coopster
<form action="<?=$PHP_SELF?>" enctype="multipart/form-data" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="300000" />
<input type="file" id="userfile" name="userfile" /> <input type="submit" value="Upload Image" />
</form>
This seems to be working, however I do not see the file in the /tmp directory even though it acknowledges "is_uploaded_file".
Trying to dump the temp file uploaded by php into a mysql blob field returns "NULL", so there is (a) no file there, (b) no permission to read the file, or (c) something else.
On a related note, I tried to change the default upload_dir in php.ini to a subdirectory of my web directory, however after restarting the web server (Apache2), the above form still ends up with the uploaded file in the /tmp directory. What am I missing?
Thanks in advance.
is_uploaded_file just tests to see if the temp file has successfully been uploaded to the server. You need to use move_uploaded_file to actually move/upload the file to a directory.
if (is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
$thisfile=$_FILES["userfile"]["tmp_name"];
$thisdesc=$_FILES["userfile"]["name"];
$path = "/home/root/public_html/dir/" . $thisdesc;
move_uploaded_file($_FILES["userfile"]["tmp_name"], $path);rest of code
Replace the path with your correct path. Think that should work.
if (is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
$thisfile=$_FILES["userfile"]["tmp_name"];
$thisdesc=$_FILES["userfile"]["name"];
$thispath="/var/www/html/uploads/".$thisdesc;
move_uploaded_file($_FILES["userfile"]["tmp_name"],$thispath);
chmod($thispath,0777);
$getdb=mysql_connect("localhost","userid","password");
$dumpblob=mysql_db_query("test","insert into blobber values (NULL,LOAD_FILE('$thispath'),'$thisdesc')") or die ("Oops: ".mysql_error()."<br />\n");
}
Now I need to get my PHP installation set up to use the GD libraries so I can SEE the graphic data stored in the db as a picture.
I appreciate your help.