首页 » PHP教程 » files怎么打印php技巧_PHP HTTP文件上传变量_FILES

files怎么打印php技巧_PHP HTTP文件上传变量_FILES

访客 2024-12-12 0

扫一扫用手机浏览

文章目录 [+]

例:

upload_file.html

files怎么打印php技巧_PHP HTTP文件上传变量_FILES

<html>

files怎么打印php技巧_PHP HTTP文件上传变量_FILES
(图片来自网络侵删)

<head>

<title>upload_file.html</title><!--标题名称为upload_file.html-->

<meta charset=\"大众utf-8\"大众><!--外部脚本文件中利用的字符编码为utf-8 中文-->

</head>

<body>

<form enctype=\"大众multipart/form-data\公众 action=\"大众upload_file.php\公众 method=\"大众post\公众><!--利用POST的办法上传文件,并通报给upload_file.php处理-->

<input type=\"大众hidden\"大众 name=\公众MAX_FILE_SIZE\公众 value=\公众32000\"大众 /><!--表示此表单中上传文件每个都不能超过32000个字节-->

上传文件: <input name=\公众sendfile\"大众 type=\公众file\公众 /><br /><!--表示上传的是文件类型,并将上传文件的详细信息存储在$_FILWS['sendfile']中-->

<input type=\"大众submit\"大众 value=\"大众上 传\"大众 /><!--表单上传按钮-->

</form>

</body>

</html>

upload_file.php

<?php

print \"大众<pre>\"大众;

$store_dir = 'd:\\wamp64\www\phptest\upload\\';//文件上传后存储在做事器的路径

$uploadfile = \"大众$store_dir\公众.basename($_FILES['sendfile']['name']);//上传文件的原始名字

$uploadfile_tmp = $_FILES['sendfile']['tmp_name']; //上传文件的临时名字

$err_msg = $_FILES['sendfile']['error']; //上传文件时产生的缺点信息

if ( $err_msg ) { //如果存在缺点代码则打印出来

print \"大众缺点代码:$err_msg<br>\公众;

}

if (!is_writeable($store_dir)){//检讨上传文件夹是否可写,不可写则打印缺点信息并退出

print \公众$store_dir 目录不可写\n\公众;

exit;

}

else {

print \"大众$store_dir 目录可写\n\"大众; //可写则打印精确信息

}

if ( isset ($_FILES['sendfile']) ) {//检讨上传文件是否存在,如存在则对其进行下一步操作

if (is_uploaded_file($uploadfile_tmp)) {

print \"大众文件考验成功\n\公众;

}

else {

print \"大众文件考验失落败,可能遭受文件上传攻击!
\公众;

exit;

}

if (move_uploaded_file($uploadfile_tmp, $uploadfile)) {//对上传的合法文件,将其重命名并移动做事器的上传文件夹中

print \"大众文件移动成功\n\"大众;

}

else {

print \"大众移动文件失落败,可能遭受文件上传攻击!
\公众;

exit;

}

print \"大众文件上载成功!
<br>\公众;

}

else {

print \"大众文件上载失落败! <br>\公众;

}

print '$_FILES=';

print_r($_FILES);//打印$_FILES数组信息

print \"大众</pre>\"大众;

?>

结果:

2.俩个文件同时上传

例:

upload_file_m.html

<html>

<head>

<title>upload_file.html</title><!--标题名称为upload_file.html-->

<meta charset=\"大众utf-8\"大众><!--外部脚本文件中利用的字符编码为utf-8 中文-->

</head>

<body>

<form enctype=\"大众multipart/form-data\"大众 action=\"大众upload_file_m.php\"大众 method=\"大众post\公众><!--利用POST的办法上传文件,并通报给upload_file_m.php处理-->

<input type=\"大众hidden\公众 name=\"大众MAX_FILE_SIZE\公众 value=\"大众1000\公众 /><!--表示此表单中上传文件每个都不能超过1000个字节-->

上传文件1: <input name=\"大众sendfile[]\"大众 type=\"大众file\"大众 /><br /><!--表示上传的是文件类型,并将上传文件的详细信息存储在$_FILWS['sendfile']中-->

上传文件2: <input name=\"大众sendfile[]\"大众 type=\公众file\公众 /><br />

<input type=\"大众submit\公众 value=\"大众上 传\"大众 /><!--表单上传按钮-->

</form>

</body>

</html>

upload_file_m.php

<?php

print \"大众<pre>\公众;

$store_dir = 'd:\\wamp64\www\phptest\upload\\';//文件上传后存储在做事器的路径

foreach ($_FILES[\"大众sendfile\"大众][\"大众error\"大众] as $key => $error) { //遍历办法取出上传文件变量数组$_FILES['sendfile']中每个error值

if ($error == UPLOAD_ERR_OK) {

$uploadfile_tmp = $_FILES['sendfile']['tmp_name'][$key];

$uploadfile = \"大众$store_dir\"大众. basename($_FILES['sendfile'][\"大众name\公众][$key]);

move_uploaded_file( $uploadfile_tmp, $uploadfile );//利用循环移动上传所有文件,从而实现对文件的保存

}

}

print '$_FILES=';

print_r($_FILES);//打印$_FILES数组信息

print \"大众<pre>\公众;

?>

结果:

标签:

相关文章

PHP顶岗实技巧_软件技能实训解决筹划2024

在这一背景下,培养高本色的软件人才显得尤为主要。为此,我国提出了一系列举措,包括加强软件国民根本教诲、深化新工科培植、加快特色化示...

PHP教程 2024-12-14 阅读0 评论0