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', '$company', '$email', '$city', $contact, '$fullpath')";
-
Bro, show some code :)aimme– aimme2015年09月06日 19:26:46 +00:00Commented 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– mustafa19932015年09月06日 19:48:54 +00:00Commented 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– aimme2015年09月06日 19:52:24 +00:00Commented 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– mustafa19932015年09月06日 19:54:28 +00:00Commented Sep 6, 2015 at 19:54
-
ok..i will help you :) working on itaimme– aimme2015年09月06日 19:55:15 +00:00Commented Sep 6, 2015 at 19:55
1 Answer 1
Its 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 components 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
PDOormysqliwith 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 :)
2 Comments
Explore related questions
See similar questions with these tags.