What are the differences between using pathinfo() and getimagesize() functions in PHP for file manipulation tasks?
When working with file manipulation tasks in PHP, the pathinfo() function is used to extract information about a file path, such as the directory name, base name, extension, etc. On the other hand, the getimagesize() function is specifically used to get the size and type of an image file. Therefore, pathinfo() is more versatile for general file manipulation tasks, while getimagesize() is specialized for images.
// Example using pathinfo()
$file_path = '/path/to/file.txt';
$file_info = pathinfo($file_path);
echo 'Directory: ' . $file_info['dirname'] . '<br>';
echo 'Base Name: ' . $file_info['basename'] . '<br>';
echo 'Extension: ' . $file_info['extension'] . '<br>';
// Example using getimagesize()
$image_path = '/path/to/image.jpg';
$image_info = getimagesize($image_path);
echo 'Image Type: ' . $image_info['mime'] . '<br>';
echo 'Image Width: ' . $image_info[0] . '<br>';
echo 'Image Height: ' . $image_info[1] . '<br>';