PHP:如何将文件保存在从python发布的文件夹中

2024-09-29 00:22:52 发布

您现在位置:Python中文网/ 问答频道 /正文

基本上,我正在使用python目录列表技术扫描整个系统,并将所有文件发送到PHP脚本,我希望将它们存储在计算机上名为project的文件夹中。我看到了我的问题的可用解决方案,但这些解决方案对我不起作用

How to upload & Save Files with Desired name

我的python脚本:

url = 'http://localhost:9090/project/php/test.php'
driveStr = subprocess.check_output("fsutil fsinfo drives")
driveStr = driveStr.decode("utf-8")
driveStr = driveStr.strip().lstrip('Drives: ')
drives = driveStr.split()
print(drives)
mylist = []
for drive in drives:
    if os.path.isdir(drive):
        p = os.walk(drive)
        for i, dirs, files in p:

            for filename in files:
                if not filename.endswith ( ".txt" ) :
                    continue
                print ( filename )
                post = { 'filename' : filename }
                req = urlencode ( post ).encode ( "utf-8" )
                req = requests.post ( url , post )

我正在扫描整个系统中的文本文件,并将这些文件发送到服务器上的PHP脚本。

我的PHP脚本:

if(isset($_POST['filename']))
{
    
    $file = $_POST['filename'];
    $dir = "C:\wamp64\www\project";
    move_uploaded_file($file, $dir);
}

它不会将这些文件存储到目标目录中。但当我将它们保存在计算机上的任何文件中时,这些文件已成功保存,但我无法将它们存储在目录中


Tags: 文件in目录project脚本forif系统