locked
How to upload image to webserver with php. RRS feed

  • Question

  • I am creating a windows store app with vb.net, I have to upload an image to a webserver via php. I use the background transfer sample to get this working but the file doesn't get saved.

    This is the log from the Background Transfer Sample:

    It seems that the file gets uploaded but it isn't saved in the 'uploads' folder on my webserver.

     Uploading 3.png to http://webserverurl.com/upload.php, 1d204f47-2b29-440f-a1e9-c1ff3dc17f8d
    Running: 1d204f47-2b29-440f-a1e9-c1ff3dc17f8d
    Progress: 1d204f47-2b29-440f-a1e9-c1ff3dc17f8d, Status: Running
     - Sent bytes: 131072 of 946355 (13.8501936376941%), Received bytes: 0 of 0
    Progress: 1d204f47-2b29-440f-a1e9-c1ff3dc17f8d, Status: Running
     - Sent bytes: 786432 of 946355 (83.1011618261646%), Received bytes: 0 of 0
    Progress: 1d204f47-2b29-440f-a1e9-c1ff3dc17f8d, Status: Running
     - Sent bytes: 946355 of 946355 (100%), Received bytes: 0 of 0
    Progress: 1d204f47-2b29-440f-a1e9-c1ff3dc17f8d, Status: Completed
     - Sent bytes: 946355 of 946355 (100%), Received bytes: 39 of 39
    Completed: 1d204f47-2b29-440f-a1e9-c1ff3dc17f8d, Status Code: 200
     - Response updated; Header count: 4

    This is my PHP code:

    <?php
    
      if ($_FILES["file"]["error"] > 0)
        {
        echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
        }
      else
        {
    
        if (file_exists("upload/" . $_FILES["file"]["name"]))
          { 
        echo $_FILES["file"]["name"] . " already exists. ";
          }
        else
          {
          move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]);
          }
        }
    ?>

    The PHP code does work when I try to upload a file via a html form.

    Thanks

    Wednesday, December 18, 2013 4:47 PM

Answers

  • Thanks for the comment, I already figured it out. There had to be added a few lines to the app code, the problem wasn't in the PHP.
    • Edited by DaanLenaerts Wednesday, December 18, 2013 10:36 PM
    • Marked as answer by DaanLenaerts Wednesday, December 18, 2013 10:38 PM
    Wednesday, December 18, 2013 10:34 PM

All replies

  • You're going to have to step through your PHP code to figure this out. 

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by DaanLenaerts Wednesday, December 18, 2013 10:34 PM
    • Unmarked as answer by DaanLenaerts Wednesday, December 18, 2013 10:37 PM
    Wednesday, December 18, 2013 8:38 PM
    Moderator
  • Thanks for the comment, I already figured it out. There had to be added a few lines to the app code, the problem wasn't in the PHP.
    • Edited by DaanLenaerts Wednesday, December 18, 2013 10:36 PM
    • Marked as answer by DaanLenaerts Wednesday, December 18, 2013 10:38 PM
    Wednesday, December 18, 2013 10:34 PM

  • What lines need to be added for Background Transfer Sample to work with php?
    Friday, December 27, 2013 3:55 PM