Home >Backend Development >PHP Tutorial >Bare-bones file upload in php

Bare-bones file upload in php

Barbara Streisand
Barbara StreisandOriginal
2024-11-19 21:57:03374browse

Bare-bones file upload in php

HTML Form

/index.html :

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <form method="post" action="upload.php" enctype="multipart/form-data">
      <label for="file-label">File : </label>
      <input type="file" name="myfile">



<h3>
  
  
  File Upload Handler
</h3>

<p>/upload.php :<br>
</p>

<pre class="brush:php;toolbar:false"><?php
$tempFile = $_FILES['myfile']['tmp_name'];
$fileName = $_FILES['myfile']['name'];

$fileDestination = __DIR__."/uploads/".$fileName;

copy($tempFile, $fileDestination);

unlink($tempFile);

Note :
An /uploads folder must be created beforehand.

The above is the detailed content of Bare-bones file upload in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn