1

like file upload there are

<?php
$_FILES['file']['tmp_name'];
$_FILES['file']['name'];
$_FILES['file']['size'];
$_FILES['file']['type'];
?>

now. i have a file that is sitting on my other web server, and i want to get the name size and mime type of that file via url.. is this possible?..

i've alreay tried to use this code below. but it doesn't work

    $url = "http://mydomain.com/myfile.rar";
    filesize ( $url );
    mime_content_type ( $url );
Vhanjan
  • 115
  • 1
  • 2
  • 10

2 Answers2

6

You can try native php function get_headers it's very fast way to read file data

RDK
  • 4,540
  • 2
  • 20
  • 29
0

You can't do it like this. The information you get when you use $_FILES is meta-information that is sent along with the file (and the size can even be calculated after the file is retrieved).

You cannot get this information like that, but you can download the actual file and inspect the header information to get that information. To do this, read about curl, which allows you to do HTTP requests to another server.

It might be possible to request just the headers, so you get the information without getting the file, which is obviously more efficient.

Another solution is to implement a file-info script on the other server that allows you to get the file info. So you could request http://mydomain.com/fileinfo.php?file=myfile.rar. In fileinfo.php you can get all the file info of the given file and just echo it.

GolezTrol
  • 114,394
  • 18
  • 182
  • 210