问题:
我做了一个表单index.html:
1<form action="process.php" enctype="multipart/form-data" method="post" name="form1">
2<table>
3<tr>
4<td><input name="pic" size="30" type="file"/></td>
5</tr>
6<tr>
7<td>
8<input id="Submit" name="Submit" type="submit" value="Send"/>
9
10<input name="Submit2" type="reset" value="Reset"/>
11</td>
12</tr>
13</table>
14</form>
提交后的处理页process.php:
1
2echo filetype($pic);
3echo basename($pic);
我在file表单域打开一个图片文件,想输出文件名和类型,但是为什么总是不能输出,结果是输出文件名为:"c:\windows\temp\php2",而文件类型为:"file"
为什么不是我的文件所在的绝对路径,和我想得到的"jpeg"类型呢,请高手帮帮我.
---------------------------------------------------------------
1
2include ("../../lib/setting.php");PangRight($SAS_SESSION[userlogin][spwd]);
3if (count($HTTP_POST_VARS)>0){
4
5if(!empty($mydocfile)){
6//echo "cp ".$attachfile." ".$mydocfile.$filename;
7copy($attachfile,$mydocfile.$filename);
8}
9if(!empty($gdocfile)){
10//echo "cp ".$attachfile." ".$gdocfile.$filename;
11copy($attachfile,$gdocfile.$filename);
12}
13if(!empty($jishufile)){
14//echo "cp ".$attachfile." ".$gdocfile.$filename;
15copy($attachfile,$jishufile.$filename);
16}
17}
1<html>
2<head>
3<title> :::::: </title>
4<meta content="text/html; charset=utf-8;
5```" http-equiv="Content-Type"/>
echo ${css_.$SAS_SESSION[language]};
1
2<script language="javascript">
3function sendform(){
4if(document.dataform.attachfile.value==''){
5alert("请添加上传文件!");
6document.dataform.attachfile.focus();
7return false;
8}
9
10var fname='';
11var str=document.dataform.attachfile.value;
12fname=str.split("\\\");
13document.dataform.filename.value=fname[fname.length-1];
14document.dataform.submit();
15
16}
17</script>
18</head>
19<body leftmargin="0" marginheight="0" marginwidth="0" topmargin="0">
20<center>
21<table border="0" cellpadding="0" cellspacing="0" width="95%">
22<tr>
23<td class="Td8">
24<table border="0" cellpadding="0" cellspacing="0" width="0">
25<tr>
26<td class="Td8" width="19"> </td>
27<td class="Td8a"><b>文档管理--文件上传</b></td>
28<td class="Td8" width="48"> </td>
29<td class="Td8"> </td>
30</tr>
31</table>
32</td>
33<td class="Td8" width="10"> </td>
34</tr>
35</table>
36</center>
37<form action="```
38 echo $PHP_SELF;
39```" enctype="multipart/form-data" method="post" name="dataform">
40<input name="filename" type="hidden"/>
41<center>
42<table border="0" cellpadding="0" cellspacing="1" class="Font12px" width="95%">
43<tr align="center"><td>
44<input ".$sas_session[userlogin][uloginid]."="" ";="" "checked";="" ```="" ```"="" class="ip2" if(!empty($mydocfile)="" name="mydocfile" type="checkbox" user="" value="```
45 echo $path->userfiles." ¦="" ¦(empty($mydocfile)&&empty($gdocfile)))echo=""/>
46上传到我的文件夹
47<input ".$sas_session[userlogin][ugroupid]."="" ";="" "checked";="" ```="" ```"="" class="ip2" echo="" group="" if(!empty($gdocfile))="" name="gdocfile" type="checkbox" value="```
48 echo $path-&gt;userfiles."/>
49上传到部门文件夹
50<input ";="" "checked";="" ```="" ```"="" class="ip2" echo="" if(!empty($gdocfile))="" jishu="" name="jishufile" type="checkbox" value="```
51 echo $path->userfiles."/>
52上传到技术文件夹
53</td></tr>
54<tr align="center"><td>
55<input name="attachfile" size="30" type="file"/>
56 <input class="ipSub" name="cmdUp" onclick="javascript:sendform();" type="button" value="提 交"/>
57</td></tr></table>
58</center>
59</form>
60</body>
61</html>
---------------------------------------------------------------
以下摘自PHP手册
上传表单:
1<form action="_URL_" enctype="multipart/form-data" method="post">
2<input name="MAX_FILE_SIZE" type="hidden" value="1000"/>
3Send this file: <input name="userfile" type="file"/>
4<input type="submit" value="Send File"/>
5</form>
我们推荐您使用 $_FILES。……
以上范例中 $_FILES 数组的内容如下所示。我们假设文件上传字段的名称如上例所示,为 userfile。
$_FILES['userfile']['name']
客户端机器文件的原名称。
$_FILES['userfile']['type']
文件的 MIME 类型,需要浏览器提供该信息的支持,例如“image/gif”。
$_FILES['userfile']['size']
已上传文件的大小,单位为字节。
$_FILES['userfile']['tmp_name']
文件被上传后在服务端储存的临时文件名。
$_FILES['userfile']['error']
可以用$uploadfile_name$uploadfile_type等等来解决,upload代表上传文件,例如问题中的:pic