Shadow_Walker Posted May 17, 2014 Share Posted May 17, 2014 Hi PHP freaks!! I have manage to make a script to upload file in database and its working. I will share to you the codes so for other viewers and readers to use also. if($result){ if($_FILES['LRCard']['name'] != ""){ $filename = $_FILES['LRCard']['name']; $ext = strrchr($filename,"."); $LRCardname = $student_id; $LRCardname .="_". $filename; if($ext ==".jpg" || $ext ==".jpeg" || $ext ==".JPG" || $ext ==".JPEG" || $ext ==".gif" || $ext ==".GIF"){ $size = $_FILES['LRCard']['size']; if($size > 0 && $size < 5000000){ $archive_dir = "LRCards"; $userfile_tmp_name = $_FILES['LRCard']['tmp_name']; if(move_uploaded_file($userfile_tmp_name, "$archive_dir/$LRCardname")){ /* if LRC is successfully uploaded then LRC is stored in database. */ mysql_query("update student_information set LRCard='$LRCardname' where student_id='$student_id'", $link_id); $flag = "success"; if(mysql_error()!=null){ die(mysql_error()); } } else{ if(file_exists('LRCard/' . $LRCardname)) { unlink('LRCards/' . $LRCardname); } rollbackData(); } } else{ if(file_exists('LRCards/' . $LRCardname)) { unlink('LRCard/' . $LRCardname); } rollbackData(); die("You can upload LRCard of 5 MB size only. Please, try again."); } } else{ if(file_exists('LRCards/' . $LRCardname)) { unlink('LRCards/' . $LRCardname); } rollbackData(); die("You can upload LRCard of .jpg, .jpeg, .gif extensions only. Please, try again. "); } } } else{ $flag="error"; } if($flag == "success"){ mysql_query(" COMMIT "); $flag="success"; if(mysql_error() != null){ die(mysql_error()); } } Now, my problem is how to make a Php script to DOWNLOAD this uploaded file considering the 1. file path 2. file name 3. file extension. 4. student_id (to determine the specific file from a specific student) My plan is to make a download button which hyperlink to download.php and after clicking that button the specified file to a specific student id will automatically be downloaded by the browser. Link to comment https://forums.phpfreaks.com/topic/288559-how-to-download-file-from-database/ Share on other sites More sharing options...
ginerjm Posted May 18, 2014 Share Posted May 18, 2014 Perhaps this google result is what you want: http://stackoverflow.com/questions/9559032/how-to-download-a-file-from-server-with-a-button-click Link to comment https://forums.phpfreaks.com/topic/288559-how-to-download-file-from-database/#findComment-1479953 Share on other sites More sharing options...
Shadow_Walker Posted June 12, 2014 Author Share Posted June 12, 2014 hello ginerjm, the link is dead Link to comment https://forums.phpfreaks.com/topic/288559-how-to-download-file-from-database/#findComment-1482530 Share on other sites More sharing options...
fastsol Posted June 12, 2014 Share Posted June 12, 2014 Here is a tutorial I have on downloading a file in php. You'll have to modify it to accomodate your database query, but the concept of the download is exactly the same either way. http://amecms.com/article/PHP-Force-File-Download-With-File-Whitelist Link to comment https://forums.phpfreaks.com/topic/288559-how-to-download-file-from-database/#findComment-1482536 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.