1

我目前制作了一个脚本,允许在我们公司内上传文件。我正在寻找改进此脚本以允许在下载链接中隐藏上传文件的目录(真的不希望人们知道目录结构)有没有办法可以对链接进行编码,然后一旦成功上传使我们的客户可以下载屏蔽的 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."; 
 } 
 } 
 ?> 

多谢你们 :)

4

2 回答 2

0

我不会给你代码,但这是我在不泄露位置的情况下实现文件共享的策略。

  1. 创建一个将要检索的文件的名称作为参数的文件。它的唯一目的是打开文件并将其流式传输。它应该提前知道如何处理文件,在哪里查找它,以及如何返回它(流)。让我们称之为getFile($filename)

  2. 在您的主 PHP 文件中,调用该函数并将结果存储在一个变量中:

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

现在将文件发送给用户,他将不知道它的来源。

于 2012-05-24T03:42:31.923 回答
0

您可以制作一个文件反弹的脚本。它只接受文件名作为参数。就像是:

下载.php?file=myfile.txt

这样你就不用说你把文件放在哪里了,而且很容易实现。您可以添加标题以实际下载文件。

于 2012-05-24T03:46:26.493 回答