所以,我在客户的网站上放了一个表格,他要我修改它以便人们可以附上一两张照片。所以我正在运行一些测试,每当我提交表单时,都会收到此错误:
警告:fopen()[function.fopen]:文件名不能为空 第32行/homepages/20/d153810528/htdocs/fabFormHandlerTEST.php
警告:fread():提供的参数不是有效的流资源 第33行/homepages/20/d153810528/htdocs/fabFormHandlerTEST.php
警告:fclose():提供的参数不是有效的流资源 第100行/homepages/20/d153810528/htdocs/fabFormHandlerTEST.php
现在,我猜测无论出于何种原因,文件名都没有从表单传递。我不是发送空白,我实际上是点击“浏览”按钮然后右转进行jpg。
首先,这是来自HTML的文件输入代码:
<td class="form">Picture #1 (optional)</td>
<td><input type="file" name="picture1" id="picture1" /></td>
当我点击“提交”时,该名称应作为“picture1”发送给表单处理程序,不是吗?
这是我处理“picture1”的PHP代码:
$file1name=$_FILES['picture1']['name'];
$file1type=$_FILES['picture1']['type'];
$file1size=$_FILES['picture1']['size'];
$file1temp=$_FILES['picture1']['tmp_name'];
以下是第32和33行,故障开始了:
$fp1=fopen($file1name,"rb");
$file1=fread($fp1,$file1size);
我尝试用$ file1temp替换fopen()函数中的$ file1name,但这并没有什么区别。
我已确认服务器设置为允许fopen()。
这是完整的表格:
<form enctype="multipart/form-data" name="contactRich" id="contactRich" method="post" action="fabFormHandlerTEST.php" onsubmit="return fabFormValidate()">
<table cellpadding="6">
<tr>
<td colspan="2"><h3>Contact</h3></td>
</tr>
<tr>
<td class="form">Your name:</td>
<td><input type="text" id="cName" name="cName" size="31"></td>
</tr>
<tr>
<td class="form">Neighborhood or closest major intersection:</td>
<td><input type="text" name="cNeighborhood" size="31"></td>
</tr>
<tr>
<td class="form">Your phone number:<br><span class="footer">(Include area code)</span></td>
<td>(<input type="text" size="3" maxlength="3" name="cAreaCode"/>) <input type="text" id="cNumber" name="cNumber" size="23" maxlength="8" onkeyup="addHyphen()"></td>
</tr>
<tr>
<td class="form">Your e-mail address:</td>
<td><input type="text" name="cEmail" size="31"></td>
</tr>
<tr>
<td class="form">What can we help you with?</td>
<td><select name="cTopic">
<option value="null">(Please choose:)</option>
<option value="an estimate">Estimate</option>
<option value="bifold doors">Bifold doors</option>
<option value="broken window ropes">Broken window ropes</option>
<option value="door that won't stay shut">My door won't stay shut!</option>
<option value="noisy doors">My door is noisy!</option>
<option value="sticking doors">My door is sticking!</option>
<option value="drywall repairs">Drywall repairs</option>
<option value="garbage disposals">Garbage disposals</option>
<option value="grab bars">Grab bars</option>
<option value="your various services">(other)</option>
</select></td>
</tr>
<tr>
<td class="form">Any additional details?</td>
<td><textarea name="cAdditional" cols="27" rows="4" wrap="soft"></textarea></td>
</tr>
<tr>
<td class="form">Picture #1 (optional)</td>
<td><input type="file" name="picture1" id="picture1" /></td>
</tr>
<tr>
<td class="form">Picture #2 (optional)</td>
<td><input type="file" name="picture1" id="picture1" /></td>
</tr>
<tr>
<td class="form">Picture #3 (optional)</td>
<td><input type="file" name="picture1" id="picture1" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit" /></td>
</tr>
<tr>
<td colspan="2"><hr /></td>
</tr>
</table>
<input type="hidden" id="isValid" name="isValid" value="no" />
</form>
答案 0 :(得分:1)
显然$file1name
中的值为空或NULL。通过临时添加print_r($_FILES);
答案 1 :(得分:0)
PHP告诉你$ file1name不包含任何内容;检查你set the correct enctype on the HTML form并查看“常见陷阱”部分。