简体   繁体   English

PHP文件上传/主机系统

[英]PHP File Upload / Host System

I have currently made a script which allows uploading for files within our company. 我目前制作了一个脚本,该脚本允许在我们公司内上传文件。 I am looking to improve this script to allow for the directory of the uploaded file to masked within the download link (Don't really want people knowing the directory structure) Is there a way I can encode the link and then once a successful upload is made echo out the masked URL available for our clients to download. 我正在寻找改进此脚本的方法,以允许将上载文件的目录掩盖在下载链接中(真的不希望人们知道目录结构)是否有一种方法可以对链接进行编码,然后成功上传后使回显的URL掩码可供我们的客户下载。

    <?php 
 $target = "upload/"; 
 $target = $target . basename( $_FILES['uploaded']['name']) ; 
 $ok=1; 

 //This is our size condition 
 if ($uploaded_size > 350000) 
 { 
 echo "Your file is too large.<br>"; 
 $ok=0; 
 } 

 //This is our limit file type condition 
 if ($uploaded_type =="text/php") 
 { 
 echo "No PHP files<br>"; 
 $ok=0; 
 } 

 //Here we check that $ok was not set to 0 by an error 
 if ($ok==0) 
 { 
 Echo "Sorry your file was not uploaded"; 
 } 

 //If everything is ok we try to upload it 
 else 
 { 
 if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
 { 
 echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; 
 } 
 else 
 { 
 echo "Sorry, there was a problem uploading your file."; 
 } 
 } 
 ?> 

Thanks Guys :) 多谢你们 :)

I won't give you the code, but here is my strategy for implementing file sharing without giving away their location. 我不会给您代码,但这是我实现文件共享而不泄漏其位置的策略。

  1. Create a file that takes as a parameter the name of the file to be retrieved. 创建一个文件,该文件将要检索的文件名作为参数。 It's only purpose is to open the file and stream it out. 唯一的目的是打开文件并将其流式传输出去。 It should know ahead of time what to do with the file, where to look for it, and how to return it(stream). 它应该提前知道如何处理文件,在哪里寻找文件以及如何返回文件(流)。 Let's call it getFile($filename) 我们称之为getFile($filename)

  2. In your main PHP file, call the function and store the result in a variable: 在您的主要PHP文件中,调用函数并将结果存储在变量中:

    $file = getFile($_POST['filename']); $ file = getFile($ _ POST ['filename']);

Now send the user the file, and he will be none the wiser about where it came from. 现在将文件发送给用户,他将不再是文件的明智之选。

You could make a script that the file bounces. 您可以创建一个文件反弹的脚本。 It just accepts the filename as parameter. 它只接受文件名作为参数。 Something like: 就像是:

download.php?file=myfile.txt download.php?file = myfile.txt

that way you don't say where you put your files, and it's easy to implement. 这样,您无需说出文件的存放位置,而且易于实现。 You could add headers to actually download the file. 您可以添加标题以实际下载文件。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM