URL上传器在没有http前缀的情况下失败

时间:2013-08-03 07:08:30

标签: php

我有以下上传程序脚本,可以将文件从远程服务器上传到我的。

    <html>
<head><title>Game Grabber</title></head>
<body>
<h3>Fast Grabber for Game uploading</h3>
    <form action="" method="post">
        Put game URL: <input type="text" name="url" />
<INPUT TYPE = "submit" Name = "submit" VALUE = "Upload">
    </form>
</body>
</html>
<?php
if($_POST['submit']){
$url = $_POST['url'];
$name = basename($url);
list($txt, $ext) = explode(".", $name);
$name = $name;


if($ext == "zip" ):

$rndname = rand(1,9999999).".".$ext;

$upload = file_put_contents("files/$rndname",file_get_contents($url));


           $zip = new ZipArchive;
           if ($zip->open("files/$rndname") === TRUE )  {
           $zip->extractTo('./files/');
           $zip->close();
           deleteinsecurefiles('./files/', 'html');
           deleteinsecurefiles('./files/', 'txt');
           deleteinsecurefiles('./files/', 'php');
           deleteinsecurefiles('./files/', 'zip');
           deleteinsecurefiles('./files/', 'rar');
           echo "The file was uploaded successfully";
}          else {
           echo 'The file was uploaded but there was a problem in the decompression"';
           deleteinsecurefiles('./files/', 'zip');
}

else:
    echo "This file type is not allowed";
endif;


}
?>

当我以这种方式放置url:http://site.com/file.zip脚本可以工作,但是当我这样说:site.com/file.zip(没有http前缀)然后我收到以下错误:

警告:file_get_contents(remoteserver.com/gamespack.zip)[function.file-get-contents]:无法打开流:/home/site/public_html/fup/uploader.php中没有这样的文件或目录15

我已经创建了必要的文件夹以及为什么它没有说明我没有说明这样的文件或目录。我的代码的第14-15行是:

(Ln14)$ rndname = rand(1,9999999)。“。”。$ ext;

(Ln15)$ upload = file_put_contents(“files / $ rndname”,file_get_contents($ url));

我做错了什么?

提前致谢

1 个答案:

答案 0 :(得分:1)

问题在于您正在使用:file_put_contents并且习惯于将“字符串写入文件”,如file_put_contents上的PHP手册所引用的那样。

虽然您应该使用move_uploaded_file代替。

string = text ,而非二进制文件,例如 ZIP 文件。