简体   繁体   English

PHP / Python下载脚本无法完成

[英]PHP/Python Download script won't finish

I'm trying to create a script so that the user can input a URL, and new file name, and that url will be downloaded (renamed as the new file name) to /var/www/dl, and a progress file (progress0001.txt ... progressXXXX.txt) will be updated as each download progresses 我正在尝试创建一个脚本,以便用户可以输入URL和新文件名,并将该URL下载(重命名为新文件名)到/ var / www / dl和一个进度文件(progress0001) .txt ... progressXXXX.txt)将随着每次下载的进行而更新

I have two files: dl.php, and rdl.py 我有两个文件:dl.php和rdl.py

dl.php: dl.php:

<?php
$name=$_GET["name"];
if (file_exists("dl/$name")){
die("FILE EXISTS");
}
else {
$str=("/var/www/rdl.py '$name' '".$_GET["url"]."'");
//echo $str;
exec("$str &");
}
?>
added

rdl.py rdl.py

#!/usr/bin/env python
import urllib, os, sys
fname=sys.argv[-2]
url=sys.argv[-1]
name="progress"
end="txt"
while os.path.isfile("/var/www/p/%s.%s"%(name, end)):
    try:
        post=int(name[-4:])
        name=name[:-4]
    except:
        post=0
    post+=1
    name="%s%04i"%(name, post)
pname="%s.%s"%(name, end)
def report(count, blockSize, totalSize):
    global pname
    percent = float(count)*blockSize*100/totalSize
    pg=open("/var/www/p/%s"%pname, "w+")
    pg.write(str(percent))
urllib.urlretrieve(url, os.path.join("/var/www/dl", fname), reporthook=report)

I can run the exact command passed to exec in the php file in a command line, and it works fine. 我可以在命令行中的php文件中运行传递给exec的确切命令,并且工作正常。 But when the PHP script executes it, I end up with a download file that exists, but is completely empty, and no progress file. 但是,当PHP脚本执行该脚本时,最终会得到一个下载文件,该文件存在,但完全为空,没有进度文件。 I have googled and tweaked this for hours and I'm at a complete loss. 我用谷歌搜索和调整了几个小时,我完全不知所措。 What is going on here? 这里发生了什么?

最终导致文件权限问题,apache没有执行脚本的权限,因为它不拥有脚本。

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

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