I have a html for that asks for username, password and image file.
Then I use this script to upload it to snapchat story:
<?php
$target_dir = "uploads/";
$target_dir = $target_dir . basename( $_FILES["uploadFile"]["name"]);
$uploadOk=1;
if (move_uploaded_file($_FILES["uploadFile"]["tmp_name"], $target_dir)) {
echo "The file ". basename( $_FILES["uploadFile"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
$user = $_POST['user'];
$pass = $_POST['pass'];
$img = $_FILES["uploadFile"]["tmp_name"];
require_once("src/snapchat.php");
$snapchat = new Snapchat($user, $pass);
$id = $snapchat->upload(Snapchat::MEDIA_IMAGE,file_get_contents($img));
$snapchat->setStory($id, Snapchat::MEDIA_IMAGE, 10);
?>
But it does not work! It keeps saying:
Warning: file_get_contents(/tmp/phpCO1pki) [function.file-get-contents]: failed to open stream: No such file or directory in /home/u753295385/public_html/run_command.php on line 18
There's probably something I'm forgetting. If you could help me that'd be AWESOME!
That's because the file is not there any more - you moved it:
if (move_uploaded_file($_FILES["uploadFile"]["tmp_name"], $target_dir)) {
This function moves the file from temporary directory somewhere else. So either do not move, or use the target location - $target_dir
.
I don't know what Snapchat is, but if you're just using the contents of the file, you don't have to move it at all. Just check for the $_FILES["uploadFile"]["error"]
and then pass the temporary name:
$id = $snapchat->upload(Snapchat::MEDIA_IMAGE,file_get_contents($_FILES["uploadFile"]["tmp_name"]));