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 7 of 7
  1. #1
    New Coder
    Join Date
    May 2009
    Posts
    26
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Absurdly simple question

    Alright, this one is easy....in the following code
    Code:
    $_FILES['file']['name']
    What is it looking for in the 'name' portion? While I'm at it, I'll make sure I understand the 'file' portion as well, though I believe that's just the name="whatever" from your HTML tag on your <input type="file" blah blah> element

    Thanks,

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Check http://php.net/manual/en/features.fi...ost-method.php
    What is it looking for in the 'name' portion? While I'm at it, I'll make sure I understand the 'file' portion as well, though I believe that's just the name="whatever" from your HTML tag on your <input type="file" blah blah> element
    That variable holds the actual name of your uploaded file.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    May 2009
    Posts
    26
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Check http://php.net/manual/en/features.fi...ost-method.php
    That variable holds the actual name of your uploaded file.
    But I see all sorts of examples online that seem to use the 'name' reference before any file uploading has taken place. I'm seeing it as an undeclared index essentially. How does 'name' know what file you're going to be uploading?

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    How does 'name' know what file you're going to be uploading?
    It gets the name only after upload, not prior to that! How about just echoing those variables and check their values?
    PHP Code:
    <?php
    echo '<pre>';
    print_r($FILES);
    echo 
    '</pre>';
    ?>
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    New Coder
    Join Date
    May 2009
    Posts
    26
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    It gets the name only after upload, not prior to that! How about just echoing those variables and check their values?
    PHP Code:
    <?php
    echo '<pre>';
    print_r($FILES);
    echo 
    '</pre>';
    ?>
    That was a great idea to print, though I'm guessing I have an empty array since it only prints "Array()". I'm using ajax to send a post from my javascript file to my php file. Is this array empty because I'm no longer in my file that has access to input type file html element?

    If I understand the purpose of the $_FILES array, I think it might be more prudent to simply pass the information across in my post rather than attempting to get it again from that array?

    Am I thinking about this correctly? Does that make sense? =P
    Last edited by sionice; 06-01-2009 at 09:22 AM.

  • #6
    New Coder
    Join Date
    May 2009
    Posts
    26
    Thanks
    2
    Thanked 0 Times in 0 Posts
    In order to post (because I don't like looking up information online to see an unanswered thread), I now understand that the purpose of the $_FILES array is to communicate information across all PHP scripts running on a given server. The information is added by the programmer, and extracted by the programmer, which was probably the most fundamental flaw in my original thinking.

    My solution is to not use the $_FILES array, rather I'm sending all the information that I require via an ajax post from javascript to php.

  • #7
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    AFAIK, XMLHttpRequest can't handle file uploads, so you need to submit your form in some way. Consider using swfupload or fancyupload (google them)
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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