欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

js动态创建上传表单通过iframe模拟Ajax实现无刷新_javascript技巧

程序员文章站 2024-01-07 19:59:52
...
复制代码 代码如下:

file.php
复制代码 代码如下:

header("content-Type: text/html; charset=Utf-8");

if(@is_uploaded_file($_FILES['inputname']['tmp_name'])){

$f = $_FILES['inputname'];
$name = $f["name"];
$size = $f["size"];
$type = $f["type"];
$fileName = $f["tmp_name"];

switch ($type) {
case 'image/jpg':$okType = true;
break;

case 'image/jpeg':$okType = true;
break;

case 'image/png':$okType = true;
break;

case 'image/gif':$okType = true;
break;
}

if($okType){
$error = $f["error"];
echo '文件名称:'.$name.'
';
echo '文件类型:'.$type.'
';
echo '文件大小:'.round($size/1024).'K
';
echo '文件临时存放路径:'.$fileName.'
';

$fileDir = dirname(__FILE__).'/img/upfile'.time().$name;
$img = explode('/',$fileDir);

move_uploaded_file($fileName, $fileDir);

$data = array();
$data['img'] = $img;
$data['name'] = $name;
$data['type'] = $type;
$data['size'] = $size;
$data['filename'] = $fileName;
$data['fileDir'] = $fileDir;

if($error==0){
/*echo '上传成功!';
echo '预览:';
echo "js动态创建上传表单通过iframe模拟Ajax实现无刷新_javascript技巧
";
echo '文件名称'.$img[2];*/
$data['error'] = 0;
exit("");

}elseif($error==1){
$data['error'] = 1;
$data['meg'] = '超过了文件大小,在php.ini文件中设置';
exit("");
}elseif ($error==2){
$data['error'] = 2;
$data['meg'] = '超过了文件的大小MAX_FILE_SIZE选项指定的值';
exit("");
}elseif ($error==3){
$data['error'] = 3;
$data['meg'] = '文件只有部分被上传';
exit("");
}elseif ($error==4){
$data['error'] = 4;
$data['meg'] = '没有文件被上传';
exit("");
}else{
$data['meg'] = '上传文件大小为0';
exit("");
}

}
}else{
$data['error'] = 4;
$data['meg'] = '没有文件被上传';
exit("");
}
?>

上一篇:

下一篇: