登录
首页 >  文章 >  php教程

php 中的简单文件上传

来源:dev.to

时间:2024-12-05 18:15:59 211浏览 收藏

来到golang学习网的大家,相信都是编程学习爱好者,希望在这里学习文章相关编程知识。下面本篇文章就来带大家聊聊《php 中的简单文件上传》,介绍一下,希望对大家的知识积累有所帮助,助力实战开发!

php 中的简单文件上传

html 表单

/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" id="myfile" />
      <input type="submit" name="submit" id="submit" value="submit" />
    </form>
  </body>
</html>

文件上传处理程序

/upload.php :

<?php
$tempFile = $_FILES['myfile']['tmp_name'];
$fileName = $_FILES['myfile']['name'];

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

copy($tempFile, $fileDestination);

unlink($tempFile);

注意:
必须事先创建 /uploads 文件夹。

到这里,我们也就讲完了《php 中的简单文件上传》的内容了。个人认为,基础知识的学习和巩固,是为了更好的将其运用到项目中,欢迎关注golang学习网公众号,带你了解更多关于的知识点!

声明:本文转载于:dev.to 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>