...

View Full Version : Absurdly simple question



sionice
06-01-2009, 09:23 AM
Alright, this one is easy....in the following 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,

abduraooft
06-01-2009, 09:37 AM
Check http://php.net/manual/en/features.file-upload.post-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.

sionice
06-01-2009, 09:46 AM
Check http://php.net/manual/en/features.file-upload.post-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?

abduraooft
06-01-2009, 09:51 AM
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
echo '<pre>';
print_r($FILES);
echo '</pre>';
?>

sionice
06-01-2009, 10:07 AM
It gets the name only after upload, not prior to that! How about just echoing those variables and check their values?

<?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

sionice
06-01-2009, 07:17 PM
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.

abduraooft
06-02-2009, 08:44 AM
AFAIK, XMLHttpRequest can't handle file uploads, so you need to submit your form in some way. Consider using swfupload or fancyupload (google them)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum