1) It is necessary to try on the simplest example, create an index.html file with the form:
<form action="server.php" method="post" enctype="multipart/form-data"> <input type="file" name="filename" /> <input type="submit" /> </form>
Note the following:
- form submission method must be POST
- The form must have an enctype attribute and the value must have a multipart / form-data
- an input with file type must also have a name attribute, the value of which will be used on the server.
After that, create 1 more server.php file in the same folder, and paste the following code into it:
<?php if(copy($_FILES["filename"]["tmp_name"],"c:/xampp/htdocs/files/".$_FILES["filename"]["name"])) { echo("файл успешно загружен"); } else { echo("Ошибка загрузки файла"); } ?>
Replace in the copy function, the path to your own, and note that in $ _FILES we pass the name that we specified in index.html in the input in the name attribute in with the file sent. It should also be noted that in the case of downloading files with the same name at different times, only the last file will remain in the download directory, the previous one will be overwritten. Therefore, as an option, you can change the file name when loading, replacing:
copy($_FILES["filename"]["tmp_name"],"c:/xampp/htdocs/files/".$_FILES["filename"]["name"])
on:
copy($_FILES["filename"]["tmp_name"],"c:/xampp/htdocs/files/".uniqid().$_FILES["filename"]["name"])
Try downloading a file weighing up to 1 MB.
The example is fully working, if it works on your server, then the environment is OK and look for an error in the code, if it does not work then you need to look for an error in the environment.
2) The second thing to check is the settings in php.ini:
max_file_uploads - maximum upload file size
post_max_size - the maximum size of data that can be transmitted via a post request
If the weight of the picture exceeds these two parameters, then you need to increase them.