0

Hi PHP expert pls help a friend. I am working with php and mysql, building a music site,

I am getting an issue with the image form of the site, if i leave the image form empty and submit the form, it create a blank black thumb, and save it as image, instead to leave the form empty since i did not filled it.

I checked the code and found some image code of resizing the image if needed which i suggest that their the ones, making this issue but i am not sure.

Here ia the code please some one should help me and fixed it Here is the code in pastebin

if(isset($_POST['submit']) and isset($_GET['add']))
{

   $artist_image=rand(0,99999)."_artist.jpg";
         
   //Main Image
   $tpath1='thumbs/orginal/'.$artist_image;              
   $pic1=compress_image($_FILES["artist_image"]["tmp_name"], $tpath1, 85);
 
    //Thumb Image 
   $thumbpath='thumbs/300/'.$artist_image;      
   $thumb_pic1=create_thumb_image($tpath1,$thumbpath,'300','300');   
   
   
   $thumbpath2='thumbs/100/'.$artist_image;     
   $thumb_pic2=create_thumb_image($tpath1,$thumbpath2,'100','100');   

    $artistlink = convert_link($_POST['artist_name']);  
   $data = array( 
            'artist_name'  =>  $_POST['artist_name'],
           'artist_image'  =>  $artist_image,
           'artist_link' => $artistlink
            );      

    $qry = Insert('tbl_artist',$data);  
  • You must check size of uploaded file $_FILES["artist_image"] If size is 0 then assign Empty/NULL value to the artist_image variable. – Prakaash Apr 14 '22 at 03:15
  • Does this answer your question? [How to check whether the user uploaded a file in PHP?](https://stackoverflow.com/questions/946418/how-to-check-whether-the-user-uploaded-a-file-in-php) – kmoser Apr 14 '22 at 04:03

1 Answers1

0

Try to add a line to check the image

if(isset($_POST["submit"])) {
  $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  if($check !== false) {
    echo "File is an image - " . $check["mime"] . ".";
    $uploadOk = 1;
  } else {
    echo "File is not an image.";
    $uploadOk = 0;
  }
}