Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python将图像发送到Web服务器上的php脚本_Php_Python_Image_Powershell_Webserver - Fatal编程技术网

使用python将图像发送到Web服务器上的php脚本

使用python将图像发送到Web服务器上的php脚本,php,python,image,powershell,webserver,Php,Python,Image,Powershell,Webserver,我制作了这个python脚本,以便使用powershell将图像发送到Web服务器上的php脚本: <?php $name = $_GET["name"]; $file = "/var/www/html/screen/" . " Screenshot " . $name; file_put_contents($file, file_get_contents('php://input')); ?> 客户端脚本: import pyautogui import subprocess i

我制作了这个python脚本,以便使用powershell将图像发送到Web服务器上的php脚本:

<?php
$name = $_GET["name"];
$file = "/var/www/html/screen/" . " Screenshot " . $name;
file_put_contents($file, file_get_contents('php://input'));
?>
客户端脚本:

import pyautogui
import subprocess
import time
import os
import getpass

directory = os.path.dirname(os.path.abspath(__file__))
whoami = cmd = subprocess.Popen("whoami", shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE, stdin=subprocess.PIPE)

user = whoami.stdout.read().decode()
user = user.split("\\")[1].replace(" ",'')
while True:
    try:
        place = directory + "\screenshot.png"
        screenshot = pyautogui.screenshot()
        screenshot.save(place)
        command = r"powershell +(New-Object System.Net.WebClient).UploadFile('http://ipwebserver/screen.php?name=".replace("+", '"') + user +  "', 'PUT','" + place +  "') > $null+".replace('+', '"')
        print(command)
        cmd = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE, stdin=subprocess.PIPE)
        time.sleep(5)
    except:
        print("error")
    continue
以及Web服务器上的PHP脚本:

<?php
$name = $_GET["name"];
$file = "/var/www/html/screen/" . " Screenshot " . $name;
file_put_contents($file, file_get_contents('php://input'));
?>
奇怪的是,它有时能起作用当我这样定义变量时:

user = "Username"
whoami = cmd = subprocess.Popen("whoami", shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE, stdin=subprocess.PIPE)

user = whoami.stdout.read().decode()
user = user.split("\\")[1].replace(" ",'')
我试图做的是从多台客户端pc接收屏幕截图,并将其保存到属于该pc用户名的文件中

我尝试了很多方法,但都不知道是什么导致了这个问题

有人有什么建议吗

旁注
我所需要的只是一种区分多台计算机的方法,我尝试了使用客户端的IP,但也没有用…

我非常欣赏这个解决方案的艺术抽象。我想问一下,为什么您同时使用Python和Powershell来完成您试图构建的解决方案?据我所知,这是使用Powershell将文件上载到Web服务器的最简单方法,而且由于我唯一的编程经验是使用Python,所以我选择了……您是否尝试过将定义好的变量输出到控制台?如果你至少能分析一下,找到一个模式,这可能会有所帮助。至于您让PS计算的powershell逻辑,我很难看到所需的输出。它至少是类似于:http:\\ipwebserver/screen.php?name=$user但还有什么?其余的对我来说看起来很神秘。我已经尝试在不同的步骤多次打印变量,我觉得没有什么不同,而且powerhsell命令工作正常,不会导致奇怪的行为。你一定有错误的模式。首先,您可以在powershell字符串中实现代码的“whoami”部分。通过使用$env:username,您可以在PS中轻松获得用户名。为您节省了几行代码,并减少了二进制代码的使用。此外,创建一个日志文件,其中包含每次运行的所有变量值,以及每次脚本失败时的错误指示器,以及脚本成功时的成功指示器。那我帮你看一下。