Sep-26-2020, 10:50 AM
I am running Windows 10 Version 10.0.18363 Build 18363.
Python 3.8.5
Apache 2.4.41
I found an example of how to copy an image to windows clipboard.
If I run the program at cmd.exe level, it works and I'm able to post the copied image from the clipboard.
If I execute the same program from within a PHP script using exec(program to run),
it runs without any errors. However the image is not in the clipboard.
I've tried creating a .bat file and then using PHP exec(.bat file), nothing is copied to the clipboard.
Again the .bat file when run at cmd.exe level, runs successfully.
I've run whoami at cmd.exe level and the correct user (ie myself as administrator) displays noellaptop\rorke
The code below my Python script.
Python 3.8.5
Apache 2.4.41
I found an example of how to copy an image to windows clipboard.
If I run the program at cmd.exe level, it works and I'm able to post the copied image from the clipboard.
If I execute the same program from within a PHP script using exec(program to run),
it runs without any errors. However the image is not in the clipboard.
I've tried creating a .bat file and then using PHP exec(.bat file), nothing is copied to the clipboard.
Again the .bat file when run at cmd.exe level, runs successfully.
I've run whoami at cmd.exe level and the correct user (ie myself as administrator) displays noellaptop\rorke
The code below my Python script.
#!c:/users/rorke/appdata/local/programs/python/python38/python.exe from io import BytesIO import win32clipboard from PIL import Image import cgi, cgitb print ("Content-type:text/html\r\n\r\n") # Create instance of FieldStorage #form = cgi.FieldStorage() #filepath = form.getvalue('image_url') filepath = "C:/wamp64/www/PhotoApp2.0/favicon.ico" #print(filepath) def send_to_clipboard(clip_type, data): win32clipboard.OpenClipboard() win32clipboard.EmptyClipboard() win32clipboard.SetClipboardData(clip_type, data) win32clipboard.CloseClipboard() print("Done!") image = Image.open(filepath) output = BytesIO() image.convert("RGB").save(output, "BMP") data = output.getvalue()[14:] output.close() send_to_clipboard(win32clipboard.CF_DIB, data)The code below is my PHP script.
<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div>
<?php
$cmd = 'powershell C:/Users/rorke/AppData/Local/Programs/Python/Python38/python.exe
C:/wamp64/bin/apache/apache2.4.41/cgi-bin/hpCopyImage.py';
echo $cmd;
exec($cmd, $out, $ret);
print_r($out);
print_r($ret);
?>
</div>
</body>
</html>