andy
andy

Reputation: 53

php server side code to upload image

     $path1='./upload/'.$userid.'/';


     if(!$path1.$category_name.'_'.$i.'_product_image1.jpg')
     {
        $file1 = fopen($path1.$category_name.'_'.$i.'_product_image1.jpg', 'wb');
        $file2 = fopen($path1.$category_name.'_'.$i.'_product_image2.jpg', 'wb');
        $file3 = fopen($path1.$category_name.'_'.$i.'_product_image3.jpg', 'wb');

        fwrite($file1, $binary1);
        fwrite($file2, $binary2);
        fwrite($file3, $binary3);

        $path = $category_name.'_'.$i;
 }
     else {"already exists";}

     $Gimage1 = mysql_real_escape_string(base_url($path1.$path.'_product_image1.jpg'));
     $Gimage2 = mysql_real_escape_string(base_url($path1.$path.'_product_image2.jpg'));
     $Gimage3 = mysql_real_escape_string(base_url($path1.$path.'_product_image3.jpg'));

     fclose($file1);
     fclose($file2);
     fclose($file3);

why is the if condition not checking whether image in that path already not exists... it simply enters into if condition so please help.

Upvotes: 0

Views: 50

Answers (1)

MSadura
MSadura

Reputation: 1042

It happens because you dont check if file exists...

if(!file_exists($path1.$category_name.'_'.$i.'_product_image1.jpg'));

Your current code checks if condition is not false, which is not (it contains not empty string with path), but it have nothing to do with the fact that file exists or not.

File exists manual

Upvotes: 2

Related Questions