简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM