栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用PHP上传文件

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用PHP上传文件

以下是一种上传文件的方法,还有许多其他方法。

正如@nordenheim所说,

$HTTP_POST_FILES
自PHP 4.1.0起已弃用,因此不建议使用。

PHP代码(upload.php)

<?php$target_dir = "upload/";$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);$uploadOk = 1;$imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);// Check if image file is a actual image or fake imageif (isset($_POST["submit"])) {    if ($target_file == "upload/") {        $msg = "cannot be empty";        $uploadOk = 0;    } // Check if file already exists    else if (file_exists($target_file)) {        $msg = "Sorry, file already exists.";        $uploadOk = 0;    } // Check file size    else if ($_FILES["fileToUpload"]["size"] > 5000000) {        $msg = "Sorry, your file is too large.";        $uploadOk = 0;    } // Check if $uploadOk is set to 0 by an error    else if ($uploadOk == 0) {        $msg = "Sorry, your file was not uploaded.";        // if everything is ok, try to upload file    } else {        if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { $msg = "The file " . basename($_FILES["fileToUpload"]["name"]) . " has been uploaded.";        }    }}?>

HTML代码启动功能

<form action="upload.php" method="post" id="myForm" enctype="multipart/form-data">    Select file to upload:    <input type="file" name="fileToUpload" id="fileToUpload">    <button name="submit"  type="submit" value="submit">Upload File</button> </form>

希望这可以帮助。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/465820.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号