Shazbot! Posted October 6, 2007 Share Posted October 6, 2007 Greetings, I need some help in with an image upload/download. I am working on a site for my wife and she needs to upload an image to a database and then download the image. php 5 with mysql 4 Problem is that when I try to display the image it shows up as garbled text (which I know is normal but I am not sure how to display it properly) The attached image is how it looks. Here is the upload code that I got from the net for uploading an image, this appears to be working. in MyPHP admin it shows the file size of the test image which looks right. mysql_select_db($database_OTH) or die( "Unable to select database"); //echo "<br />"; //echo "something else"; $fileName = $_FILES['imagefile']['name']; $tmpName = $_FILES['imagefile']['tmp_name']; $fileSize = $_FILES['imagefile']['size']; $fileType = $_FILES['imagefile']['type']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } require_once('DBConnect'); $File_SongName="Unknown"; if(isset($_POST['File_SongName'])) { $File_SongName=$_POST['File_SongName']; } $File_SongVersion="1"; if(isset($_POST['File_SongVersion'])) { $File_SongVersion=$_POST['File_SongVersion']; } $File_Uploaded_By=$_SESSION['FULLNAME']; $TimeStamp=date('M-d-Y')." ".date('h:i:s A'); echo $_SESSION['FULLNAME']; $query = "INSERT INTO TableName(File_Name, File_Size , File_Type , File_Contents, File_Uploaded_By, File_SongName, File_SongVersion, File_Date_Uploaded) ". "VALUES ('$fileName', $fileSize, '$fileType', '$content', '".$_SESSION['FULLNAME']."', '$File_SongName', '$File_SongVersion', '$TimeStamp')"; mysql_query($query) or die('Error, query failed'); echo "<br>File $fileName uploaded<br>"; Here is the code to display the data through a download page: mysql_select_db($database_OTH) or die( "Unable to select database"); $query="SELECT File_ID, File_Name, File_Size FROM TableName WHERE File_ID=32";//.$_GET['FileID']; $SQL_Query=mysql_query($query) or die('Error, query failed'); while($Results=mysql_fetch_array($SQL_Query)) { //echo $Results['File_Name']; // echo "<br />"; //echo $Results['File_Size']; //echo "<br />"; header ("Content-Type: ".$Results['File_Type']."\n"); header ("Content-disposition: attachment; filename=\"".$Results['File_Name']."\"\n"); header ("Content-Length: ".$Results['File_Size']."\n"); readfile ($Results['File_Contents']); Thank you in advance for anyone that can help me. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/72059-image-upload-download/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.