<script> <br>window.onload=function(){ <br>upfile('file.php'); <br>} <br><br><br>/* <br>** url 路径 <br>**/ <br>function upfile(url){ <br>//创建iframe <br>var iframe = document.createElement("iframe"); <br>document.body.appendChild(iframe); <br>iframe.id = 'iframeName'; <br>iframe.name = 'iframeName'; <br>iframe.style.display = '없음'; <br>//创建form <br>varturnForm = document.createElement("form"); <br>document.body.appendChild(turnForm); <br>turnForm.method = '게시물'; <br>turnForm.action = url; <br>turnForm.encoding = "다중 부분/양식-데이터"; <br>turnForm.name = 'formNamer'; <br>turnForm.target = 'iframeName'; <br>//创建隐藏表单 <br>var newElement = document.createElement("input"); <br>newElement.setAttribute("이름","입력 이름"); <br>newElement.setAttribute("type","file"); <br>newElement.setAttribute("value",''); <br>turnForm.appendChild(newElement); <br>} <br><br>//form提交 <br>function formSubmit() { <br>//var res = document.formNamer.inputname.value; <br>document.formNamer.submit(); <br>} <br><br>//返回值 <br>함수 콜백(결과){ <br>//window.parent.document.getElementById('iframeName').style.display = 'block'; 일반적인 iframe 查看后台数据 <br>if(result['error'] == 0){ <br>document.getElementById('test').src= result['img'][1] '/' result[' img'][2]; <br>}else if(result['error'] == 1){ <br>alert(result['meg']); <br>}else if(result['error'] == 2){ <br>alert(result['meg']); <br>}else if(result['error'] == 3){ <br>alert(result['meg']); <br>}else if(result['error'] == 4){ <br>alert(result['meg']); <br>}else{ <br>alert(결과['meg']); <br>} <br><br>} <br><br></script>
上传
header("content-Type: text/html; charset=Utf-8");
if(@is_uploaded_file($_FILES['inputname']['tmp_name'])){
$f = $_FILES['inputname'];
$이름 = $f["이름"];
$size = $f["size"];
$유형 = $f["유형"];
$fileName = $f["tmp_name"];
스위치($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 = dirname(__FILE__).'/img/upfile'.time().$name;
$img = 폭발('/',$fileDir);
move_uploaded_file($fileName, $fileDir);
$data = 배열();
$data['img'] = $img;
$data['이름'] = $이름;
$data['유형'] = $유형;
$data['크기'] = $크기;
$data['filename'] = $fileName;
$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>");
}
}
}else{
$data['error'] = 4;
$data['meg'] = '전체 내용이 있음';
exit("<script>parent.callback(".json_encode($data).");</script>");
}
?>