-1

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!

Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
Olav Alberts
  • 71
  • 1
  • 1
  • 3

1 Answers1

1

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"]));
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
  • Oh, another comment editor... Please post code at external site. Post it before posting the comment. I will not dissapear in few secconds, so there's no hurry. – Tomáš Zato Oct 19 '14 at 18:21
  • I updated my script, now it gives me no error, but doesn´t upload to pic to snapchat either. (snapchat is an app like instagram etc) – Olav Alberts Oct 19 '14 at 18:22
  • Well, that's a different problem. I never used it, so I can't help, especially since there's no error. Try to dump the image to the output by `imagepng(imagecreatefromstring(file_get_contents(//path//)))` – Tomáš Zato Oct 19 '14 at 18:23
  • I don't know what that means :( – Olav Alberts Oct 19 '14 at 18:24
  • That means: Your question was solved. Ask another, after you find out some errors ("It's not working" question will be closed here). Or join some IRC channel where somebody may help you with subsequent problems. – Tomáš Zato Oct 19 '14 at 18:28
  • Hey! it's working, it only uploads jpg though, it wont work when I use PNG. Is there anyway to only allow jpg or automatically change the extension to jpg? – Olav Alberts Oct 19 '14 at 18:28
  • Changing extension is pointless. JPG and PNG are diferent way of saving the image. Extension is just part of filename. You can give it `.txt` and it's till an image. – Tomáš Zato Oct 19 '14 at 18:29
  • Ok but when I change the extension from png to jpg it works, it seems to work even if it's just a part of the filename and nothing more. – Olav Alberts Oct 19 '14 at 18:33
  • Well, somebody is cheating during the check. – Tomáš Zato Oct 19 '14 at 18:35