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;
休息;
case 'image/jpeg':$okType = true;
休息;
case 'image/png':$okType = true;
休息;
case 'image/gif':$okType = true;
休息;
}
if($okType){
$error = $f["error"];
echo '檔案名稱:'.$name.'
';
echo '檔案類型:'.$type.'
';
echo '檔案大小:'.round($size/1024).'K
';
echo '檔案暫時存放路徑:'.$fileName.'
';
$fileDir = 目錄名(__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['檔名'] = $檔名;
$data['fileDir'] = $fileDir;
if($error==0){
/*echo '上傳成功! ';
echo '預覽:';
echo "
";
echo '檔案名稱'.$img[2];*/
$data['error'] = 0;
exit("<script>parent.callback(".json_encode($data).");</script>");
}elseif($error==1){
$ data['error'] = 1;
$data['meg'] = '超過了檔案大小,在php.ini檔案中設定';
exit("<script>parent.callback(". json_encode($data).");</script>");
}elseif ($error==2){
$data['error'] = 2;
$data['meg '] = '超過了檔案的大小MAX_FILE_SIZE選項指定的值';
exit("<script>parent.callback(".json_encode($data).");</script>");
}elseif ($error==3){
$data['error'] = 3;
$data['meg'] = '檔案只有部分已上傳';
exit("<script>parent.callback(".json_encode($data).");</script>");
}elseif ($error==4){
$data['error'] = 4;
$data['meg'] = '沒有檔案上傳';
exit("<script>parent.callback(".json_encode($data).");</script>");
}else{
$data['meg'] = '上傳檔案大小為0';
exit("<script>parent.callback(".json_encode($data).");</script>");
}
}
}其他{
$data['error'] = 4;
$data['meg'] = '沒有檔案上傳';
exit("<script>parent.callback(".json_encode($data).");</script>");
}
? >