尝试从允许更多输入的表单上传文件

时间:2015-06-20 00:13:20

标签: php

我需要允许管理员在管理区域中上传尽可能多的图片。我正在使用一个允许他们按下链接的代码,它会添加另一个上传按钮。然后我将其发布到PHP脚本上传文件。但是,它不是上传它们,它甚至不打印我的错误消息。任何帮助都会很棒。

以下是表单代码的剪辑:

<tr>
<td width="280" bgcolor="#e1e1e1"><font color="#000000">Product Image:</font></td>
<td width="615" bgcolor="#e1e1e1">
<div id="newlink">
<div class="feed">
<input name="image[]" type="file" />
</div>
</div>
<p id="addnew">
<a href="javascript:add_feed()">Add Another Image </a>
</p>
<div id="newlinktpl" style="display:none">
<div class="feed">
<input name="image[]" type="file" />
</div>
</div>
</td></tr>

以下是上传文件的PHP代码:

$len = count($_POST['image']);
    for ($i=0; $i < $len; $i++)
    {
    $imagefile=$_POST['image'][$i];
        //if ($i == 0){$imgfile = $_POST['image'][$i];}
        //else {$imgfile = $imgfile."|".$_POST['image'][$i];}

$target2 = "../lp/companyuploads/images/";
$target2 = $target2 . basename( $_FILES[$imagefile]['name']) ;
 $ok=1; 
 # Limit file type condition 
 if ($uploaded_type =="text/php"){ 
 echo "No PHP files<br>"; 
 $ok=0; 
 } 
 # Check that $ok was not set to 0 by an error 
 if ($ok==0){ 
 Echo "Sorry your PDF file was not uploaded"; 
 } 
 # If everything is ok upload it 
 else {
 if(move_uploaded_file($_FILES[$imagefile]['tmp_name'], $target2)) {
 $name = basename( $_FILES[$imagefile]['name']) ; 
# Show success on screen
echo <<<END
<font size="+1" color="blue" face="Arial">$name has been uploaded successfully.</font>
END;
 } 
 else 
 { 
 echo "The ".$namefile." was not saved correctly, please let Randy know you got this error."; 
 } 
 }  
}

0 个答案:

没有答案