我有一个网址,像这样:PHP查找扩展没有扩展名
$file="http://example.com/307i215/sn9gyyzpry09m3e97z6hhbnw84i215";
它要么是一个图像或视频,但它并没有在URL中的扩展。
如何从url获得该文件的扩展名,以便我可以使用正确的扩展名保存它?
$extension=?;
copy($file,"newname.$extension");
我有一个网址,像这样:PHP查找扩展没有扩展名
$file="http://example.com/307i215/sn9gyyzpry09m3e97z6hhbnw84i215";
它要么是一个图像或视频,但它并没有在URL中的扩展。
如何从url获得该文件的扩展名,以便我可以使用正确的扩展名保存它?
$extension=?;
copy($file,"newname.$extension");
您可以使用
$file="http://example.com/307i215/sn9gyyzpry09m3e97z6hhbnw84i215";
//copy file to server
$type= mime_content_type($file)
//rename file based on the type
输出
image/gif
我发现您的信息,另一种解决方案:
$extension=get_headers($file,1)["Content-Type"];
复制前会输出image/gif
。
你有没有试过[mime-content-type](http://php.net/manual/de/function.mime-content-type.php)? –