PHP中$ _FILES的问题

I am trying to make a site where I can upload pictures.

<form action="edit.php" method="get" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" value="submit">
</form>

In the edit.php-file I have chosen to use the example from W3Schools (http://www.w3schools.com/php/php_file_upload.asp). When I get to the editor-page it won't upload because the file is a invalid type (filetype not found in the array).

After many different tries I putted this code at the top of the file:

if (!isset($_FILES['file'])) { die("Not found!"); }

When I loaded the editor page again I got the error-message I had put there myself. It seems like the file I am sending from the index.php-page won't be founded in edit.php.

Can anyone help me?

It should be like this and then in your edit.php file you can try to print the $_FILES array.

//edit.php
print '<pre>';
print_r($_FILEs);


// index.php
<html>
<body>

<form action="edit.php" method="post" enctype="multipart/form-data">
  <label for="file">Filename:</label>
  <input type="file" name="file" id="file"><br>
  <input type="submit" name="submit" value="Submit">
</form>

</body>
</html> 
if(!empty($_FILES['file']['size'])):

$file = $_FILES['file']['tmp_name'];
//play with the file then
endif;

Change this line

<form action="edit.php" method="get" enctype="multipart/form-data">

to

<form action="edit.php" method="post" enctype="multipart/form-data">

See here for discussion on this topic. File uploading using GET Method

Use post method. index.php code :

<form enctype="multipart/form-data" action="edit.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

edit.php (Just printed Files array and output is as follows) Code: "; print_r($_FILES); print ""; ?>

Output : Array ( [uploadedfile] => Array ( [name] => ipmsgclip_r_1398851755_0.png [type] => image/png [tmp_name] => /tmp/phpktZwLl [error] => 0 [size] => 155 ) )

If file uploading has any error then it will come in this array as [error]. For instance : I your uploaded file's size is exceeds the mentioned file size (1000000) Then output Array will be : Array ( [uploadedfile] => Array ( [name] => d.png [type] => [tmp_name] => [error] => 2 [size] => 0 ) )