I am creating an admin interface for a content mangement web site. I am attempting to create an image upload feature to add images to articles via a web form. The form calls 'uploadimages.php'. which is designed to move the uploaded file to a directory on the server, while inserting the file name into a MySQL database.

For some reason I cannot access the $HTTP_POST_FILES array of the uploaded image.

At the beginning of my code, I am running a check to see that the array has elements:

if(!isset($HTTP_POST_FILES['picture']['name']))
{
     echo 'No name found.';
     exit;
}

When the form calls this page 'uploadimages.php', it displays 'No name found.' and exits, as though the $HTTP_POST_FILES name element is empty.

The URL in the browers shows:

uploadimages.php?pic1=C%3A%5CMy+Documents%5Cadmintitle.gif&pic2=&pic3=&Submit=Submit

What am I doing wrong here? The URL shows the information that is being passed from the form, but I cannot access the $HTTP_POST_FILES array to work with the file.

Your help is appreciated!

Devin

    Make sure your form resembles this:

    <form enctype="multipart/form-data" action="URL" method="post">
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
    </form>

    amc

      If you are expecting a variable in the URL, that is the GET Array and not the POST Array.

      Also, you should refer to the superglobal GET and POST arrays via the non deprecated method ($GET['variable'] and $POST['variable'])

      The $HTTP*VARS method is deprecated.

      Also, put in

      print_r($POST);
      print_r($
      GET);

      This will show you the content of each array.

        Thanks guys, that got me on the right track for sure. Ran into one more problem once the file was uploaded:

        Here is the code for working with the uploaded file:

        $filename = "/articles/images/$id.jpg";
        							move_uploaded_file($HTTP_POST_FILES['picture']['tmp_name'], $filename);
        

        the $id variable was defined earlier in the script.

        Here is the error codes I get:

        "Warning: move_uploaded_file(/articles/images/43.jpg): failed to open stream: No such file or directory"

        Warning: move_uploaded_file(): Unable to move '/tmp/phpLremwc' to '/articles/images/43.jpg'

        As you can see, the temporary file has been created, but cannot be moved to the new directory. I know for a fact that the directory '/articles/images' does exist. Any ideas? Thanks!

        Devin

          This isn't related to your problem, but I urge you to use the $POST instead of $HTTP_POST_FILES. You can read all about it in the PHP Manual. Search it for "Predefined Variable" and there are good articles discussing the differences (The biggest one being that the HTTP*_VARS is deprecated... Code for the today and tomorrow, not the yesterday.

            Write a Reply...