0

ive edited this question as it was pretty long!

im trying now to simply read the file info inputted to a input type="file" using php:

if(isset($_FILES['input-file'])){

$file_name = $_FILES['input-file']['name']; 
$file_size =$_FILES['input-file']['size']; 
$file_tmp =$_FILES['input-file']['tmp_name']; 
$file_type=$_FILES['input-file']['type'];

echo($file_name);
echo($file_size);
echo($file_tmp);
echo($file_type);
}

with a html form:

<form enctype="multipart/form-data" name="theform" method="post" action="image-upload-test2.php">
      <div id="container">
                <div id="input_template" style="display:none;">
                    <div class="file-container">
                        <div class="file-info"></div>
                        <div class="file-browse">Browse</div>
                        <div class="file-clear">X</div>
                    </div>
                    <input type='file' name="input-file" class="file-input-hidden" />
                </div>
      </div>
<input type="submit" name="submit" value="submit" />
</form>

but I only ever get '0' echo'ed out, which ive managed to find out is the $file_size variable through elimination.

whats going wrong?

6
  • I would suggest that you just var_dump your $_FILES['files'] before the loop and see what you get. Commented Feb 10, 2013 at 18:15
  • 3
    $_FILES['files']['tmp_name'] is not an array. Commented Feb 10, 2013 at 18:16
  • 1
    i get: array(5) { ["name"]=> string(0) "" ["type"]=> string(0) "" ["tmp_name"]=> string(0) "" ["error"]=> int(4) ["size"]=> int(0) } when i var_dump $_FILES['files'], which means its empty right? Commented Feb 10, 2013 at 18:25
  • Following your edition, it seems to me that you do not need any foreach. You just need to do this: $file_name = $_FILES['files']['name']; $file_size =$_FILES['files']['size']; $file_tmp =$_FILES['files']['tmp_name']; $file_type=$_FILES['files']['type']; Commented Feb 10, 2013 at 19:08
  • using this, it doesnt work, but weirdly i echo the $file_name variable and it gives me 'Array'? Commented Feb 10, 2013 at 19:45

2 Answers 2

2

Instead of on

$_FILES['files']['tmp_name']

You should loop on

$_FILES['files']

or just

$_FILES
Sign up to request clarification or add additional context in comments.

1 Comment

Yep. foreach only works on arrays, and $_FILES['files']['tmp_name'] is a string.
0

Yeah just print_r/var_dump the $_FILES and see if something's inthere. Also, check if your HTML form has enctype="multipart/form-data" inthere.

1 Comment

ive done that and i get: Array ( [input-file] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) ) which i believe error 4 means their is no file uploaded.. not sure whats going on

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.