【发布时间】:2014-02-09 15:25:06
【问题描述】:
我创建了一个简单的upload.php 文件。 但是我想创建一个文件托管站点,用户可以在该站点上上传文件而无需登录/注册并获取下载链接,以便其他人可以使用该链接下载他们的文件。就像在 datafilehost.com 上一样。
我的 html 文件是:-
<form enctype="multipart/form-data" action="upload.php" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" />
</form>
我的简单 php 文件是:-
<?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.";
}
}
?>
请帮帮我………… 谢谢。
【问题讨论】:
-
您面临什么问题以及在哪里遇到问题?
-
确定如果他们上传了一张图片,这只会显示图片而不是提供下载吗?在这种情况下,可以使用 htaccess 解决问题
-
if ($uploaded_type =="text/php")- 这远非充分和充分的检查,它迟早会在你的脸上炸毁。我建议你不要“创建一个文件托管网站”,只要你的知识太少。 -
另外一点,使用这个脚本,如果我上传了一个可执行文件,我可以在你的服务器上做任何事情。
标签: php file file-sharing self-hosting