Benim koduyla yanlış bir şey?

0 Cevap php

İşte ben im işe bekliyorduk ama bir yerde bir hata olmalı, yapılan kodudur. Kendimi çözemiyorum, yardım edin.

<?php

if(isset($_POST['submit'])){

    $max_size = 500000;
    $image_upload_path = "images/products/";
    $allowed_image_extension = array('jpg','jpeg','png','gif');


    for($i=0;$i<2;$i++)
    {
         //check if there is file 
        if((!empty($_FILES['image[]'][$i])) && ($_FILES['image[]']['error'][$i]==0))
        {
            //check extension
            $extension = strrchr($_FILES['image']['name'][$i], '.');
            if(in_array($extension,$allowed_image_extension))
            {
                //check file size.
                if($_FILES['image']['size'][$i] > $max_size)
                {
                    echo "file too big";
                }
                else if($_FILES['image']['size'][$i] < 1)
                {
                    echo "file empty";
                }
                else
                {
                    //we have pass file empty check,file extension check,file size check.
                    $the_uploaded_image = $_FILES['image']['tmp_name'][$i];
                    $the_uploaded_image_name = $_FILES['image']['name'][$i];

                    //replace empty space in filename with an underscore '_'
                    $the_uploaded_image_name = preg_replace('/\s/','_',$the_uploaded_image_name);

                    //get the file extension
                    $the_uploaded_image_extension = explode(',',$the_uploaded_image_name);
                    $the_new_image_name = $the_uploaded_image_name."".md5(uniqid(rand(),true))."".$the_uploaded_image_extension;

                    $save_image_as = $the_new_image_name;
                    //check file exist
                    if(file_exists($image_upload_path."".$the_new_image_name))
                    {
                        echo "file".$image_upload_path."".$the_new_image_name." already exist";
                    }
                    else
                    {
                        if(move_uploaded_file($the_uploaded_image,$save_image_as))
                        {
                            echo "image".$the_uploaded_image_name." uploaded sucessfully";
                            //set the image  path to save in database column
                        }
                        else
                        {
                            echo "there was an error uploading your image.";
                        }
                    }
                }
            }
            else
            {
            echo "extension not allowed";
            }
        }
        else
        {
            echo "please choose file to upload";
        }
    }


}

?>

<html>
<head><title>image upload</title></head>
<body>
<form action="" method="POST" enctype="multipart/form-data">
    <input type="file" name="image[]"/>
    <input type="file" name="image[]"/>
    <input type="submit" value="submit"/>
</form>
</body>
</html>

Bu benim yeni PHP kodudur. Not found bulduk Im sonucu hem alıyorum. Birisi ben burada yanlış ne yapıyorum bana söyleyecek. Else if koşul hem koşulların çıktıya veriyoruz gibi çalışmıyor gibi görünüyor. Neden?

<?php
if(isset($_POST["submit"])) {
    echo $_POST["submit"];
    echo "<br/>";
    for($i=0;$i<count($_FILES['image'])-1;$i++)
    {
        if(!empty($_FILES['image']['tmp_name'][$i]))
        {
            echo "found";    
            echo "<br/>";
        }
        else
        {
            echo "not found";
            echo "<br/>";
        }
    }

}
else
{
    echo "form is not posted";
}

>

0 Cevap