How to retrieve files from server folder using PHP and displaydownload it on a webpage using javascript? - Stack Overflow

I have build a website where a user can upload user information like name, contact etc. and upload a re

I have build a website where a user can upload user information like name, contact etc. and upload a resume in pdf format which am storing in a "uploads" folder and storing its full path in database column.

I want to build a simple website interface that will retrieve all files along with user info (am having path of all files in database as mentioned above) and display it on interface. How can I achieve it using PHP and javascript?

PS : Am using godaddy.

Here is how I uploaded file :

$path = "/home/easyemployment/public_html/uploaded/";
$tmp  = $_FILES['userfile']['tmp_name'];
$fileName = $_FILES['userfile']['name'];
move_uploaded_file($tmp, $path.$fileName);
$fullpath = $path.$fileName;
$query="INSERT INTO seeker VALUES ('$unm', '$pany', '$email', '$city', $contact, '$fullpath')"; 

I have build a website where a user can upload user information like name, contact etc. and upload a resume in pdf format which am storing in a "uploads" folder and storing its full path in database column.

I want to build a simple website interface that will retrieve all files along with user info (am having path of all files in database as mentioned above) and display it on interface. How can I achieve it using PHP and javascript?

PS : Am using godaddy.

Here is how I uploaded file :

$path = "/home/easyemployment/public_html/uploaded/";
$tmp  = $_FILES['userfile']['tmp_name'];
$fileName = $_FILES['userfile']['name'];
move_uploaded_file($tmp, $path.$fileName);
$fullpath = $path.$fileName;
$query="INSERT INTO seeker VALUES ('$unm', '$pany', '$email', '$city', $contact, '$fullpath')"; 
Share Improve this question edited Sep 6, 2015 at 19:47 mustafa1993 asked Sep 6, 2015 at 19:25 mustafa1993mustafa1993 5611 gold badge6 silver badges19 bronze badges 7
  • Bro, show some code :) – aimme Commented Sep 6, 2015 at 19:26
  • I just want some way of retrieving file and download it via javascipt. I googled it but cannot find what I need. – mustafa1993 Commented Sep 6, 2015 at 19:48
  • with javascript( client side script) its not possible to manipulate server. if it is possible it would be a security hole. but the server automatically throws files when we are on the link. – aimme Commented Sep 6, 2015 at 19:52
  • Yes I know it. Its possible through PHP something like fileread(), which PHP will echo and used by javascipt. I cannot find proper resource/tutorial for this. – mustafa1993 Commented Sep 6, 2015 at 19:54
  • ok..i will help you :) working on it – aimme Commented Sep 6, 2015 at 19:55
 |  Show 2 more ments

1 Answer 1

Reset to default 2

Its very broad so i will try to brief.

Here is the steps you could follow

  1. As you said you have already created uploading and inserting ponents and it works. So i will leave that part and go directly to the next step. What you want to achieve is show the saved data along with the uploaded file.

  2. So you need to first retrieve the saved data (user info and folder path to the cv) from database table. To do this use PDO or mysqli with php. User Select query to select matching content from database table. See Selecting table data with PDO statements

  3. User HTML and CSS to design the user interface. Show the fetched data to the design through php. including the download link to the pdf file. i will show an example of php download file below. see How to make PDF file downloadable in HTML link?

Link to the pdf download could be like this

 <a href="download.php?file=pdffilename">Download CV</a>

download.php could be like this

header("Content-Type: application/octet-stream");

$file = $_GET["file"] .".pdf";
header("Content-Disposition: attachment; filename=" . urlencode($file));   
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");            
header("Content-Length: " . filesize($file));
flush(); // this doesn't really matter.
$fp = fopen($file, "r");
while (!feof($fp))
{
    echo fread($fp, 65536);
    flush(); // this is essential for large downloads
} 
fclose($fp); 

I hope this help :)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745168421a4614774.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信