1

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')"; 
asked Sep 6, 2015 at 19:25
7
  • Bro, show some code :) 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. 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. 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. Commented Sep 6, 2015 at 19:54
  • ok..i will help you :) working on it Commented Sep 6, 2015 at 19:55

1 Answer 1

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 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.

  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 :)

answered Sep 6, 2015 at 20:23
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for such concise answer. One doubt still remains, Where have we used path to file? Download.php received just the filename not path like /upload/cv/
When the user passes filename or a specific id, to download.php, its a job of download.php to find that specific file.its the safe way, else you could provide user with direct path to file in the link and when the user clicks the link the whole link to be sent to download.php

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.