How to upload files in PHP
Автор: PHP Explained
Загружено: 2025-05-05
Просмотров: 128
Описание:
PHP file upload is possible in two steps process. In step 1, we create a form and select the file to upload. In step 2, we upload the file to the server.
Let's see the form first.
Take a closer look at the form tag. Form method must be post. Form enctype should be multipart/form-data that indicates which content type to use when submitting the form. We are using input type file to select the file.
lt;form action="upload.php" method="post" enctype="multipart/form-data"gt;
Select image to upload:
lt;input type="file" name="file"gt;
lt;input type="submit" value="Upload Image" name="submit"gt;
lt;/formgt;
Now, we select the file to upload and click on submit button to save the file in the server.
Function move_uploaded_file() is used to file upload. It has two parameters. The source path of the file. The target or saving path of the file in the server.
$file_source = $_FILES["file"]["tmp_name"];
$file_target = "uploads/" . $_FILES["file"]["name"];
if (move_uploaded_file($file_source, $file_target))
{
echo "File uploaded successfully";
}
else
{
echo "File does not upload";
}
This is how we can upload a file in PHP. It's really simple and cool.
Повторяем попытку...

Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: