使用php从url检索文件信息

i am trying to retrieve information of file from the url containing the file. but how can i get the information of file before downloading it to my server. i need file information like file size,file type etc

i had found the code to validate and download file but how to get information from it before downloading file actually to server

<?php
function is_url_exist($url)
    {
    $ch = curl_init($url);    
    curl_setopt($ch, CURLOPT_NOBODY, true);
    curl_exec($ch);
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if($code == 200)
        {
        $status = "true";
        }
    curl_close($ch);
    if ( $status == true)
        {
        $name = "abc.png";
        if (file_put_contents("uploads/$name", file_get_contents($url)))
            echo "file uploaded";
        else
            echo "error check upload link";
        }
    }
$url = "http://theonlytutorials.com/wp-content/uploads/2015/06/blog-logo1.png";
echo is_url_exist($url);
?>

for this you can fech site headers that will tell all the details of the file i.e size file type etc....

you can do this in php by fetching headers by

format to fech headers is get_headers($url) or get_headers($url) and as the code shown in the previous answer is correct

<?php
   $url = "http://theonlytutorials.com/wp-content/uploads/2015/06/blog-logo1.png";
$headers = get_headers($url,1);
print_r($headers);
?>

this will give you data in array/json format that will store all the required details you need..

you can refer to http://php.net/manual/en/function.get-headers.php for details

you can get all information of remote file by get_headers function. Try following code to find out type, content length etc.

$url = "http://theonlytutorials.com/wp-content/uploads/2015/06/blog-logo1.png";
$headers = get_headers($url,1);
print_r($headers);

Know more about get_headers click http://php.net/manual/en/function.get-headers.php