使用PHP制作文件上传,使用PHP上传文件

小编典典

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

正如@nordenheim所说,$HTTP_POST_FILES自PHP 4.1.0起已弃用,因此不建议使用。

PHP代码(upload.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 image

if (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代码启动功能

Select file to upload:

Upload File

希望这可以帮助。

2020-05-26

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值