Edit: I ended up making a variable just for jpg since that's all I'm going to be uploading. Working fine now. Thanks.

I can't seem to get an extension for my images when it's uploaded. When my image upload it gets saved as a md5 name but no extension. How do I retrieve my extension?

if (is_uploaded_file ($_FILES['image']['tmp_name'])) {

//Newname
$newname = md5(time()*rand(999,999));

//Move image over
if (move_uploaded_file($_FILES['image']['tmp_name'], $_SERVER['DOCUMENT_ROOT'].'/images/'.$newname)) {
	echo '<p>Image uploaded!</p>';

} else { 
	$errors[] = 'Could not move image';

}
} else {
	$errors[] = 'No image uploaded';
}

    Here's a function I use that may help...

    function get_extension($file,$length=-1){ 
      $p = strrpos($file,"."); 
      $p++; 
      if($length!=-1){ 
        $ext = substr($file,$p,$length); 
      } 
      if($length==-1){ 
        $ext = substr($file,$p); 
      } 
      $ext = strtolower($ext); 
      return $ext; 
    }
    

    get_extension('file.jpg'); would return ".jpg"...

      Here's a function I use that may help...

      Actually, you can just use [man]pathinfo/man.

      get_extension('file.jpg'); would return ".jpg"...

      pathinfo('file.jpg', PATHINFO_EXTENSION) would return "jpg".

        Write a Reply...