所以,我在客户的网站上放了一个表格,他要求我修改它,以便人们可以附上一两张照片。所以我正在运行一些测试,每当我提交表单时,我都会收到这个错误:
警告: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>