I have an index.php
and upload.php
. In index.php
is a form action="upload.php"
with input type="file" id="file" name="file"
tag in it. PHP code is:
<?php
$file = $_FILES['file'];
print_r($file);
echo "test";
?>
For some reason it shows echo
but print_r()
doesn’t work.
I’ve tried rewriting the code. Adding other identificators for the input
tag inside index.php
but it still doesn’t work. What am I doing wrong?
3
Answers
you are forgot enctype="multipart/form-data"
try this version
You did not mention what type of file is being uploaded. Here is an example of a image upload. With multiple image selections allowed.
And the upload PHP:
To ascertain the type of image uploaded:
Assuming that you can already upload the file, such as using form like the following:
Then if you want to display the image at the receiving "upload.php", you may use:
If the image is JPG/JPEG type:
If the image is PNG type:
Note: actually we usually save the uploaded file in the server (for later display), or store the binary data into a BLOB field in a db table, but the above code is to demonstrate how one can do to immediately display the uploaded image.