Upload image file in Windows Phone 7 Application to PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sharmashrayansh
    New Member
    • Mar 2013
    • 1

    Upload image file in Windows Phone 7 Application to PHP

    I am trying to upload a picture from the Pictures Library (on WP7) and save it in a folder on the server.

    On the server, I'm using PHP to receive the file using POST Method. The PHP Code is:
    Code:
    <?php
    $uploads_dir = 'files/'; //Directory to save the file that comes from client application.
    if ($_FILES["file"]["error"] == UPLOAD_ERR_OK) {
        $tmp_name = $_FILES["file"]["tmp_name"];
        $name = $_FILES["file"]["name"];
        move_uploaded_file($tmp_name, "$uploads_dir/$name");
    }
    ?>
    I've already tried some approaches, but they all just seem to fail. I've already done this job in a Windows Forms application using the Client.UploadFi le method but it seems that it cannot be used on a Windows Phone Application.

    I think httpwebrequest can help, right?

    This is my C# code so far:
    Code:
    public partial class SamplePage : PhoneApplicationPage
        {
            public SamplePage()
            {
                InitializeComponent();
            }
    
            PhotoChooserTask selectphoto = null;
    
            private void SampleBtn_Click(object sender, RoutedEventArgs e)
            {
                selectphoto = new PhotoChooserTask();
                selectphoto.Completed += new EventHandler<PhotoResult>(selectphoto_Completed);
                selectphoto.Show();
            }
    
            void selectphoto_Completed(object sender, PhotoResult e)
            {
                if (e.TaskResult == TaskResult.OK)
                {
                    BinaryReader reader = new BinaryReader(e.ChosenPhoto);
                    image1.Source = new BitmapImage(new Uri(e.OriginalFileName));
                    txtBX.Text = e.OriginalFileName;
                }
            }
        }
    I read it somewhere that the image is required to be converted to a string of bytes, I don't know for sure. But, please help me.

    Thanks a lot in advance.
Working...