admin管理员组文章数量:1415655
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
1 Answer
Reset to default 2Its very broad so i will try to brief.
Here is the steps you could follow
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.
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
ormysqli
with php. User Select query to select matching content from database table. See Selecting table data with PDO statementsUser 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 :)
本文标签:
版权声明:本文标题:How to retrieve files from server folder using PHP and displaydownload it on a webpage using javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745168420a2645823.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论