upload files frustration

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dandan2907
    New Member
    • Feb 2008
    • 4

    upload files frustration

    Hi all
    I am trying to upload images to a remote server and it fails all the time.
    My $_FILES array looks as follows
    [php]
    [thumbnail] => Array
    (
    [name] => 01.jpg
    [type] => image/jpeg
    [tmp_name] => d:\upload_tmp\p hp5F90.tmp
    [error] => 0
    [size] => 1268
    )

    [bigPic] => Array
    (
    [name] => 01.jpg
    [type] => image/jpeg
    [tmp_name] => d:\upload_tmp\p hp5F91.tmp
    [error] => 0
    [size] => 1268
    )
    [/php]
    It contains both pics I want to load and it seems Valid(no error flag)

    The upload file is called "http://www.o-shan.com/DBImages/eYkrAkfFHFyNybz Q8Nfn.jpg"

    meaning I use the command
    [php]if (move_uploaded_ file($_FILES[$fieldName]['tmp_name'], $uploadfile))[/php]
    Sending the tempfile to the mentioned location

    The condition statement always fails!!!!
    (The permissions are fine)
    Any ideas?
    How can I debug it?
    Tnx
    Danny
    Last edited by ronverdonk; Feb 24 '08, 12:50 PM. Reason: makeup of text
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Originally posted by dandan2907
    Hi all
    I am trying to upload images to a remote server and it fails all the time.
    My $_FILES array looks as follows
    [php]
    [thumbnail] => Array
    (
    [name] => 01.jpg
    [type] => image/jpeg
    [tmp_name] => d:\upload_tmp\p hp5F90.tmp
    [error] => 0
    [size] => 1268
    )

    [bigPic] => Array
    (
    [name] => 01.jpg
    [type] => image/jpeg
    [tmp_name] => d:\upload_tmp\p hp5F91.tmp
    [error] => 0
    [size] => 1268
    )
    [/php]
    It contains both pics I want to load and it seems Valid(no error flag)

    The upload file is called "http://www.o-shan.com/DBImages/eYkrAkfFHFyNybz Q8Nfn.jpg"

    meaning I use the command
    [php]if (move_uploaded_ file($_FILES[$fieldName]['tmp_name'], $uploadfile))[/php]
    Sending the tempfile to the mentioned location

    The condition statement always fails!!!!
    (The permissions are fine)
    Any ideas?
    How can I debug it?
    Tnx
    Danny
    It'd be nice to see the rest of your code...
    We aren't magicians.

    Comment

    • dandan2907
      New Member
      • Feb 2008
      • 4

      #3
      Originally posted by markusn00b
      It'd be nice to see the rest of your code...
      We aren't magicians.
      Sure mate

      The following is the code for extracting the data from the file control:
      ($data['name'] is the text in the control itself)

      function getData($data,$ fieldName)
      {
      global $uploaddir,$db;

      //Get data from the file control
      $imageName = $data[name];

      //a new image is set and waiting in the file control
      if ($imageName)
      {
      //get the image type
      $arr = explode('.',$im ageName);
      $imageType = $arr[count($arr)-1];

      //create a file name
      $fileName = generateRandomN ame(20).'.'.$im ageType;

      //create the file name with full path
      $uploadfile = $uploaddir . $fileName;

      echo is_uploaded_fil e($_FILES[$fieldName]['tmp_name']).'<br>';
      print_r($_FILES );
      echo "<br>$uploadfil e";
      //move file to new location
      if (move_uploaded_ file($_FILES[$fieldName]['tmp_name'], $uploadfile))
      {
      echo "File is valid, and was successfully uploaded.\n";

      //insert file data to images table
      $fieldNameArr = array();
      $fieldValsArr = array();
      array_push($fie ldNameArr,'file Name');
      array_push($fie ldValsArr,'"'.$ fileName.'"');

      $db->insert('images ',$fieldNameArr ,$fieldValsArr) ;
      }

      else
      {
      echo "Possible file upload attack!\n";
      return NULL;
      }
      return '"'.$fileName.' "';
      }
      else
      return NULL;
      }
      }

      Any ideas?

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Adding code tags (please remember to use these...)
        [php]
        function getData($data,$ fieldName)
        {
        global $uploaddir,$db;

        //Get data from the file control
        $imageName = $data[name];

        //a new image is set and waiting in the file control
        if ($imageName)
        {
        //get the image type
        $arr = explode('.',$im ageName);
        $imageType = $arr[count($arr)-1];

        //create a file name
        $fileName = generateRandomN ame(20).'.'.$im ageType;

        //create the file name with full path
        $uploadfile = $uploaddir . $fileName;

        echo is_uploaded_fil e($_FILES[$fieldName]['tmp_name']).'<br>';
        print_r($_FILES );
        echo "<br>$uploadfil e";
        //move file to new location
        if (move_uploaded_ file($_FILES[$fieldName]['tmp_name'], $uploadfile))
        {
        echo "File is valid, and was successfully uploaded.\n";

        //insert file data to images table
        $fieldNameArr = array();
        $fieldValsArr = array();
        array_push($fie ldNameArr,'file Name');
        array_push($fie ldValsArr,'"'.$ fileName.'"');

        $db->insert('images ',$fieldNameArr ,$fieldValsArr) ;
        }

        else
        {
        echo "Possible file upload attack!\n";
        return NULL;
        }
        return '"'.$fileName.' "';
        }
        else
        return NULL;
        }
        }
        [/php]
        Now i shall have a look through.

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Can you re-explain the problem?
          Try and be concise and precise.

          Also, do you get any errors?

          Comment

          • dandan2907
            New Member
            • Feb 2008
            • 4

            #6
            Thanks for the patience
            My problem is that I don't have any indication for any problem on script.

            I get a temporary file path on the "$_FILES" array.

            Still the move_uploaded_f ile command fails - It returns False and does not upload the files to my desired directory.

            If I had any error notification I could try and fix it.

            The above code should work. Has anyone encountered similar problems and managed to solve them?
            Thanks
            Danny

            Comment

            • dandan2907
              New Member
              • Feb 2008
              • 4

              #7
              Hi
              I have solved it but in a very wiered way.
              I am using relative path - ../DBImages instead of a standard url.
              It works and can suffice but if you have a clue of what is going on I would be happy to hear (I think there is a way of configuring the path on server)
              Yours
              Danny

              Comment

              • Markus
                Recognized Expert Expert
                • Jun 2007
                • 6092

                #8
                You'd be able to upload files to any server if you used direct urls!
                (or atleast try :P )

                Comment

                Working...