Web Analytics Made Easy -
StatCounter using input type=file - CodingForum

Announcement

Collapse
No announcement yet.

using input type=file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • using input type=file

    Hello,

    I am trying to get a handle on the "input type = file" tag. What I'd like to do is allow the user to upload an image file, and subsequently display the image in the gaining page.

    Essentially, the code I'm using is like so:
    [page1.php]
    PHP Code:
    ...
    <
    form action="page2.php" method="post" enctype="multipart/form-data">
        
    Image to Upload <input type="file" name="impath" />
    ... 
    [page2.php]
    PHP Code:
    ...
    <img src="<?php print $_POST['impath']; ?>" />
    ...
    which gives me nothing. I've also tried:
    PHP Code:
    ...
    <?php print $_POST['impath']; ?>
    ...
    which just gives me the filename of the file submitted, and not its contents. I would've expected the previous to give me at least a long string of binary data. What gives? Would appreciate any help.

    AT

  • #2
    heres a really nice tutorial on uploading files in php4
    http://www.zend.com/zend/spotlight/uploading.php
    anthony

    Comment


    • #3
      That works beautifully, thank you.
      One side note - tracing down the $HTTP_POST_FILES they use in the code samples, php.net had this to say:


      The Variables defined for uploaded files differs depending on the PHP version and configuration. The autoglobal $_FILES exists as of PHP 4.1.0 The $HTTP_POST_FILES array has existed since PHP 4.0.0. These arrays will contain all your uploaded file information. Using $_FILES is preferred. If the PHP directive register_globals is on, related variable names will also exist. register_globals defaults to off as of PHP 4.2.0.

      Replaced all instances of $HTTP_POST_FILES with $_FILES, still worked beautifully. Others may read more about it here .

      Thanks again,

      AT

      Comment

      Working...
      X