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

Bare-bones file upload in php

Barbara Streisand
Release: 2024-11-19 21:57:03
Original
364 people have browsed it

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);
Copy after login

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!

source:dev.to
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template