Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2003
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 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
    Regular Coder
    Join Date
    Dec 2002
    Location
    Minneapolis, MN
    Posts
    208
    Thanks
    0
    Thanked 1 Time in 1 Post
    heres a really nice tutorial on uploading files in php4
    http://www.zend.com/zend/spotlight/uploading.php
    anthony

  • #3
    New to the CF scene
    Join Date
    Jun 2003
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •