Skip to content

Instantly share code, notes, and snippets.

@Jbithell
Last active September 10, 2016 18:42
Show Gist options
  • Save Jbithell/5ace47e34f424c7eea851f4c27355b98 to your computer and use it in GitHub Desktop.
Save Jbithell/5ace47e34f424c7eea851f4c27355b98 to your computer and use it in GitHub Desktop.
Raspberry Pi - Photo Booth!

Make sure you run chmod -R 777 uploads/ and change line 5 of upload.py to the target machine's IP!

<?php
//DISPLAY THE LATEST 4 IMAGES IN THE DIRECTORY
$DISPLAY = array();
$FILES = scandir("uploads/", SCANDIR_SORT_DESCENDING);
for ($x = 0; $x < 4; $x++) {
$DISPLAY[] = $FILES[$x];
}
foreach ($DISPLAY as $image) {
echo '<img src="uploads/' . $image . '" style="width: 100%;" alt="Image" />';
}
?>
<meta http-equiv="refresh" content="2" />
Fill this file with this image: http://placekitten.com/1000/1000
<?php
//FOR THE PYTHON SCRIPT TO UPLOAD TO
$target_dir = "uploads/";
$target_file = $target_dir . time() . "." . pathinfo($_FILES["file"]["name"],PATHINFO_EXTENSION);
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) die("INCORRECT FILE TYPE");
// Check if $uploadOk is set to 0 by an error
if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) echo "1";
else echo "ERROR";
?>
#!/usr/bin/env python
#The Python Upload Script
import requests
url = 'http://URLHERE/upload.php'
files = {'file': open('kitten.jpg', 'rb')}
r = requests.post(url, files=files)
if (r.text == "1"):
print("Success")
else:
print("FAIL_FAIL_FAIL")
@Jbithell
Copy link
Author

image

Tested & confirmed to be working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment