在PHP中的image_15之后上传将无效

时间:2013-04-24 10:57:55

标签: php mysql loops for-loop uploading

我有点难过,因为我有一段运行循环的代码:

for($i=1; $i<=30; $i++) {
    if(!empty($_FILES['image_'.$i]['name'])) {
        copy($_FILES['image_'.$i]['tmp_name'], WEB_UPLOAD."/images/products/".$_FILES['image_'.$i]['name']) or die("Error uploading image.");
        $ext = strtolower(substr($_FILES['image_'.$i]['name'], strrpos($_FILES['image_'.$i]['name'], ".")));
        $image = "".text_to_url_image($name)."_product_".$i."_".$id."_large".$ext;
        $image_medium = "".text_to_url_image($name)."_product_".$i."_".$id."_medium".$ext;
        $image_small = "".text_to_url_image($name)."_product_".$i."_".$id."_small".$ext;

        rename(WEB_UPLOAD."/images/products/".$_FILES['image_'.$i]['name'], WEB_UPLOAD."/images/products/".$image); 

        $scale = '74x74';
        $go = WEB_UPLOAD.'/images/products/'.$image;
        $stop = WEB_UPLOAD.'/images/products/'.$image_small;
        exec("/usr/bin/convert $go -resize $scale\> -quality 100 $stop");
        unset($scale, $go, $stop);

        $scale = '158x158';
        $go = WEB_UPLOAD.'/images/products/'.$image;
        $stop = WEB_UPLOAD.'/images/products/'.$image_medium;
        exec("/usr/bin/convert $go -resize $scale\> -quality 100 $stop");
        unset($scale, $go, $stop);

        $scale = '620x500';
        $go = WEB_UPLOAD.'/images/products/'.$image;
        $stop = WEB_UPLOAD.'/images/products/'.$image;
        exec("/usr/bin/convert $go -resize $scale\> -quality 100 $stop");
        unset($scale, $go, $stop);

        chmod(WEB_UPLOAD."/images/products/".$image_small, 0777);
        chmod(WEB_UPLOAD."/images/products/".$image_medium, 0777);
        chmod(WEB_UPLOAD."/images/products/".$image, 0777);
        mysql_query("UPDATE `products` SET image_".$i."='".$image."' WHERE id='".$id."'");
    }
}

这适用于image_1到image_15,但是当我尝试上传image_16或更高版本的图像时,它不上传图像或将其输入SQL?表格如下:

for($i=1; $i<=30; $i++) {
    echo "<tr><td valign=\"top\">Gallery Image [".($i)."]:</td><td valign=\"top\">";
        echo "<input type=\"file\" name=\"image_".$i."\">";
        if(!empty($r['image_'.$i])) {
            echo "<br /><img src=\"".WEB_URL."/images/products/".$r['image_'.$i]."\" height=\"150\" />";
            echo "<a href=\"./?action=edit_products&id=".$id."&delete_image=image_".$i."\"><img src=\"images/delete.gif\"></a>";
        }
    echo "</td></tr>";
}

有什么想法吗?

谢谢,皮特

0 个答案:

没有答案