shikhartandon Posted September 25, 2009 Share Posted September 25, 2009 Hi, I recently switched from PHP4 to PHP5.3 The code which used to upload a pic into a data base and retrieve it do not work here.. Can any one help debug this.. TO UPLOAD $data = addslashes(fread(fopen($userfile, "r"), filesize($userfile))); $result=MYSQL_QUERY("INSERT INTO ppicture (Email,titletext,bin_data,filename,filesize,filetype) ". "VALUES ('$Email','$title','$data','$userfile_name','$userfile_size','$userfile_type')"); if(!$result) { $result=MYSQL_QUERY("UPDATE ppicture set titletext='$title',bin_data='$data',filename='$userfile_name',filesize='$userfile_size',filetype='$userfile_type' WHERE Email='$Email' " ); } TO RETRIEVE $query = "select bin_data,filetype from ppicture where Email='$Email'"; $result = MYSQL_QUERY($query); $data = MYSQL_RESULT($result,0,"bin_data"); $type = MYSQL_RESULT($result,0,"filetype"); Header( "Content-type: $type"); print $data; Is there something i should change here? Link to comment https://forums.phpfreaks.com/topic/175471-need-help-with-file-uploading/ Share on other sites More sharing options...
5kyy8lu3 Posted September 25, 2009 Share Posted September 25, 2009 you could try file_get_contents() update: i also wanted to ask, what's the error or problem you're getting/having? Link to comment https://forums.phpfreaks.com/topic/175471-need-help-with-file-uploading/#findComment-924640 Share on other sites More sharing options...
herghost Posted September 25, 2009 Share Posted September 25, 2009 Try This: To Upload: if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $fileName = $_SESSION['username'] ; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); $query = "INSERT INTO upload (name, size, type, content, post_no) VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$post_no')"; mysql_query($query) or die("oh dear " .mysql_error()); To Download <?php include('../include/dbconnect.php'); $id=$_GET['id']; $query = "SELECT name, type, size, content " . "FROM upload WHERE post_no = '$id'"; $result = mysql_query($query) or die('Error, query failed'); list($name, $type, $size, $content) = mysql_fetch_array($result); header("Content-length: $size"); header("Content-type: $type"); header("Content-Disposition: attachment; filename=$name"); echo $content; ?> Obviously you will have to change various bits like your file name and database info but that should do the trick! Link to comment https://forums.phpfreaks.com/topic/175471-need-help-with-file-uploading/#findComment-924642 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.