为什么我通过file控件把附件post到server端时不是数组,而是一个串? 难道csdn这里人气这么差?半天没有一个回复,自己拱一下吧 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <html><head><title>上载文件表单</title></head> <body> <form enctype=\"multipart/form-data\" action=\"upload.php\" method=\"post\"> <input type=\"hidden\" name=\"max_file_size\" value=\"100000\"> <center>请选择文件: <input name=\"userfile\" type=\"file\"> <input type=\"submit\" value=\"上传文件\"> </center> </form> </body> </html> 你的文件上传到SERVER了么? axolo(七月十五)因为是个串,文件当然无法上传到server了。我的form和你的一样,贴出来,各位高手看看哪里出了问题: <form name="form2" method="post" enctype='multipart/form-data'> <table width="100%"> <p> $intro </p> <p> 标 题: <input type="text" tabindex="1" name="title" size="60" maxlength="100" value="" id="sfocus" class=lanyu> <select name="selectsort" class=lanyu>$optionlist</select> </p> <tr> <td align="left" width="92%"> 内 容:<textarea name="concent" cols="80" rows="20" class=lanyu></textarea> </td> </tr> -----------这一段是我附件上传的部分---------- <tr> <td align="left" width="92%"> 附 件:<input type=file class=lanyu size='60' name=atc_attachment1> </td> </tr> ------------------------------------ <tr bgcolor="#FFFFFF"> <td width="88%"> <input type="submit" name="Submit" value="提交" class='button'> <input type="hidden" name="action" value="postnew"> <input type="hidden" name="aid" value="$dbartic[id]"> <input type="hidden" name="$msg_ruser" value="$dbartic[author]"> </td> </tr> <tr bgcolor="#FFFFFF"> <td width="12%"> </td> <td width="88%"> </td> </tr> </table> </form> 你的$_FILE里是什么东西?还有,有没有看过手册里关于文件上传的部分 文件上传表单:<form enctype="multipart/form-data" action="_URL_" method="POST"><input type="hidden" name="MAX_FILE_SIZE" value="30000">Send this file: <input name="userfile" type="file"><input type="submit" value="Send File"></form>处理表单:<?php// 在 4.1.0 以前的 PHP 中,需要用 $HTTP_POST_FILES 代替 $_FILES。// 在 4.0.3 以前的 PHP 中,需要用 copy() 和 is_uploaded_file() 来代替 move_uploaded_file()。$uploaddir = '/var/www/uploads/';$uploadfile = $uploaddir. $_FILES['userfile']['name'];print "<pre>";if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $_FILES['userfile']['name'])) { print "File is valid, and was successfully uploaded. Here's some more debugging info:\n"; print_r($_FILES);} else { print "Possible file upload attack! Here's some debugging info:\n"; print_r($_FILES);}print "</pre>";?> ps:请参阅php手册19. 文件上传处理^_^ 还是没有解决,怀疑是php的配置问题。但只是猜测 你server端的code贴出来。如何认为它是一个串的? 文件在我的网站的时候,在接收的时候,我将其echo出来,就是一个串,在我本地的环境,同样的地方echo出来是一个array。 楼上大侠,可能我没有一次表达清楚,现在把我的问题再描述一下,假设A为我的本地环境,B为我的网站空间环境。1. 在A环境下,附件上载没有任何问题。客户端代码我在上面贴除了2. 当同样的代码运行在B环境的时候,附件上载不能成功,经过跟踪,php接收file控件attachment的时候,attachment是一个字符串。而在我A环境中(附件能够成功上载)接收的attachment是一个array。我想问题出现在这里。3. 我A环境的php版本和配置,与B环境的php版本和配置都不太一样。我怀疑是配置或版本的问题,要不怎么解释同样的代码会有两个结果。我想解决的是:就是附件能够在B环境上载成功。不管是修改配置或者修改我的源代码也好,我想知道问题出现在哪里。前面有一位大侠指点我跟踪一下server端 _$FILES的变量,结果发现在B环境下,echo _$FILES得到为空。咋回事啊,已经被困了一个星期了。 问题解决了。_$FILES 应该已经传进来了,但是@extract($_FILES,EXTR_SKIP);这个并不能得到我的attachment变量。必须要赋值一次,才能得到也就是说我加了一条语句$attachment=$_FILES['attachment'];我的attachment才导出来。但为什么extract在B环境下无法导出符号表呢?哪位达人能够给解释一下。 用CURL 怎么得到URL连接的HTML代码? 如何实现无刷新的用户名检测! php读取excel文件出错 php定时生成html 如何把unixode解码成可读文本? 验证码问题 关于用数据库存储变量名的问题 各位大哥,如何在PHP中用类 求将图象上传至mysql的上传,存贮,输出,全部原程序极详细说明急!最好是立刻能用! 计算订单总数和总金额 如何用PHP创建文件夹? 急求:gb2312.txt文档
因为是个串,文件当然无法上传到server了。我的form和你的一样,贴出来,各位高手看看哪里出了问题:
<form name="form2" method="post" enctype='multipart/form-data'>
<table width="100%">
<p>
$intro
</p>
<p>
标 题: <input type="text" tabindex="1" name="title" size="60" maxlength="100" value="" id="sfocus" class=lanyu>
<select name="selectsort" class=lanyu>$optionlist</select>
</p> <tr>
<td align="left" width="92%">
内 容:<textarea name="concent" cols="80" rows="20" class=lanyu></textarea>
</td>
</tr>
-----------这一段是我附件上传的部分----------
<tr>
<td align="left" width="92%">
附 件:<input type=file class=lanyu size='60' name=atc_attachment1>
</td>
</tr>
------------------------------------
<tr bgcolor="#FFFFFF">
<td width="88%">
<input type="submit" name="Submit" value="提交" class='button'>
<input type="hidden" name="action" value="postnew">
<input type="hidden" name="aid" value="$dbartic[id]">
<input type="hidden" name="$msg_ruser" value="$dbartic[author]">
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="12%"> </td>
<td width="88%"> </td>
</tr>
</table>
</form>
还有,有没有看过手册里关于文件上传的部分
<form enctype="multipart/form-data" action="_URL_" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="30000">
Send this file: <input name="userfile" type="file">
<input type="submit" value="Send File">
</form>处理表单:
<?php
// 在 4.1.0 以前的 PHP 中,需要用 $HTTP_POST_FILES 代替 $_FILES。
// 在 4.0.3 以前的 PHP 中,需要用 copy() 和 is_uploaded_file() 来代替 move_uploaded_file()。$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir. $_FILES['userfile']['name'];
print "<pre>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $_FILES['userfile']['name'])) {
print "File is valid, and was successfully uploaded. Here's some more debugging info:\n";
print_r($_FILES);
} else {
print "Possible file upload attack! Here's some debugging info:\n";
print_r($_FILES);
}
print "</pre>";
?> ps:请参阅php手册19. 文件上传处理^_^
如何认为它是一个串的?
1. 在A环境下,附件上载没有任何问题。客户端代码我在上面贴除了
2. 当同样的代码运行在B环境的时候,附件上载不能成功,经过跟踪,php接收file控件attachment的时候,attachment是一个字符串。而在我A环境中(附件能够成功上载)接收的attachment是一个array。我想问题出现在这里。
3. 我A环境的php版本和配置,与B环境的php版本和配置都不太一样。我怀疑是配置或版本的问题,要不怎么解释同样的代码会有两个结果。
我想解决的是:就是附件能够在B环境上载成功。不管是修改配置或者修改我的源代码也好,我想知道问题出现在哪里。前面有一位大侠指点我跟踪一下server端 _$FILES的变量,结果发现在B环境下,echo _$FILES得到为空。咋回事啊,已经被困了一个星期了。
但为什么extract在B环境下无法导出符号表呢?哪位达人能够给解释一下。