代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form method="post" action="?" enctype="multipart/form-data">
上传封面:<input type="file" name="myfile"/><br/><br/>
<input type="hidden" value="1" name="go">
<input type="submit" value="上传"/><br/><br/>
</form>
</body>
</html>
<?php
if(!empty($_POST['go']) && $_POST['go']!==1){
$fileinfo=$_FILES['myfile'];
$filename=$fileinfo['name'];
$tmp_name=$fileinfo['tmp_name'];
$size=$fileinfo['size'];
$error=$fileinfo['error'];
$type=$fileinfo['type'];
$maxsize=10485760;
$allowExt=array('jpeg', 'jpg', 'png', 'gif');
$ext=pathinfo($filename, PATHINFO_EXTENSION);
$path = "./img/";
if(!file_exists($path)) {
mkdir($path,0777,true);
chmod($path, 0777);
}
$uniName=md5(uniqid(microtime(true),true)).".$ext";
$destination=$path."/".$uniName;
if($error==0){
if ($size>$maxsize) {
exit ("上传文件过大!");
}
if (!in_array($ext, $allowExt)) {
exit ("非法文件类型");
}
if (!is_uploaded_file($tmp_name) ) {
exit ("上传方式有误,请使用post方式");
}
if (!getimagesize($tmp_name) ) {
exit ("不是真正的图片类型");
}
if (move_uploaded_file($tmp_name, $destination)) {
echo "<script>parent.document.all.imgname.value = '$destination';</script>;
文件".$filename."上传成功!";
}else{
echo "文件".$filename."上传失败!";
}
}else{
switch ($error) {
case 1:
$max_upload = ini_get('upload_max_filesize');
exit("文件大小超过php.ini限制(最大 { $max_upload})");
case 2:
exit("文件大小超过表单MAX_FILE_SIZE限制");
case 3:
exit("文件只有部分被上传,请重新上传");
case 4:
exit("没有选择要上传的文件");
case 6:
exit("服务器临时文件夹不可用");
case 7:
exit("文件写入失败,可能是磁盘空间不足");
case 8:
exit("文件上传被PHP扩展阻止");
default:
exit("上传错误(错误代码: { $error} )");
}
}
}
?>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。