简体   繁体   English

如何使用PHP从服务器文件夹中检索文件并使用javascript在网页上显示/下载文件?

[英]How to retrieve files from server folder using PHP and display/download it on a webpage using javascript?

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. 我已经建立了一个网站,用户可以在其中上传用户信息,例如姓名,联系方式等,并以pdf格式上传简历,该简历存储在“上载”文件夹中,并将其完整路径存储在数据库列中。

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? 如何使用PHP和javascript实现它?

PS : Am using godaddy. PS:我正在使用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')"; 

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. 因此,您需要首先从数据库表中检索保存的数据(用户信息和cv的文件夹路径)。 To do this use PDO or mysqli with php. 为此,请使用PDOmysqli与php。 User Select query to select matching content from database table. 用户选择查询以从数据库表中选择匹配的内容。 See Selecting table data with PDO statements 请参阅使用PDO语句选择表数据

  3. User HTML and CSS to design the user interface. 用户HTML和CSS来设计用户界面。 Show the fetched data to the design through php. 通过php将获取的数据显示给设计。 including the download link to the pdf file. 包括pdf文件的下载链接。 i will show an example of php download file below. 我将在下面显示php下载文件的示例。 see How to make PDF file downloadable in HTML link? 请参阅如何使HTML链接中的PDF文件可下载?

Link to the pdf download could be like this 链接到pdf下载可能是这样的

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

download.php could be like this download.php可能像这样

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 :) 我希望这个帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在网页中执行“javascript:__doPostBack”以使用 selenium 下载 pdf 文件? - How to execute “javascript:__doPostBack” in a webpage to download pdf files using selenium? 使用 Javascript 将多个文件下载为 zip 文件或文件夹中的文件? - Download multiple files as a zip or in a folder using Javascript? 如何使用javascript下载网页的整个HTML? - How to download entire HTML of a webpage using javascript? 如何使用 PHP 从文件夹显示轮播 - How to display carousel from folder using PHP 使用 $_GET PHP/Javascript 下载 .php 文件 - Download .php files using $_GET PHP/Javascript 使用javascript和C#从文件服务器下载文件 - Download files from file server using javascript and C# 如何使用PHP检索MySQL中的表行并使用Javascript显示它? - How to retrieve table rows in MySQL using PHP and Display it with Javascript? 我可以使用javascript \\ php从URL将文件下载到服务器吗 - Can I download a file from URL to a server using javascript\php 使用Javascript或PHP从网页保存图像 - Save Images from a webpage using Javascript or PHP Javascript / PHP-使用PHP从服务器检索数据并使用Javascript生成/重新排列是个好主意吗? - Javascript/PHP - Is it good idea to retrieve data from a server using PHP and generate/rearrange it using Javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM