php如何获取kb的web图像大小?
getimagesize 只获得宽度和高度.
并filesize造成waring.
$imgsize=filesize("http://static.adzerk.net/Advertisers/2564.jpg");
echo $imgsize;
Run Code Online (Sandbox Code Playgroud)
Warning: filesize() [function.filesize]: stat failed for http://static.adzerk.net/Advertisers/2564.jpg
有没有其他方法来获得kb的Web图像大小?
可能重复:
PHP:无需下载文件的远程文件大小
当用户输入他在其他站点上传的文件的链接时,我想从PHP中找到文件的大小.但是怎么样?
我想获得远程文件的最后修改时间.我正在使用我在stackoverflow上找到的代码
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,$url);
//don't fetch the actual page, you only want headers
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_HEADER, true);
//stop it from outputting stuff to stdout
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// attempt to retrieve the modification date
curl_setopt($curl, CURLOPT_FILETIME, true);
$result = curl_exec($curl);
echo $result;
$info = curl_getinfo($curl);
print_r($info);
if ($info['filetime'] != -1) { //otherwise unknown
echo date("Y-m-d H:i:s", $info['filetime']); //etc
}
Run Code Online (Sandbox Code Playgroud)
这段代码的问题我一直在获得filetime = -1.但是当我删除
curl_setopt($curl, CURLOPT_NOBODY, true);
Run Code Online (Sandbox Code Playgroud)
然后我得到正确的修改时间.
是否有可能获得最后修改时间但是
curl_setopt($curl, CURLOPT_NOBODY, true);
Run Code Online (Sandbox Code Playgroud)
包含在脚本中.我只需要页面的标题,而不是正文.
提前致谢
背景:我想看看如何使用我的 Google Photos 空间,我用 Python 编写了一个小脚本,它使用 Google Photos API 来检索我的所有相册及其内容(使用https://developers.google.com/photos /library/reference/rest/v1/mediaItems/search)。文件信息不存在,但使用mediaItem baseUrl(记录的https://developers.google.com/photos/library/reference/rest/v1/mediaItems#MediaItem)然后我可以执行HEAD请求并content-length从标头中获取文件信息。这对于照片来说似乎效果很好,但视频的大小被严重低估了。我的猜测是,Google Photos 正在准备流式传输视频,并且不会发送整个视频信息。
问题:有没有办法检索存储在 Google Photos 上的视频的文件大小,希望不必下载整个视频?该应用程序确实知道文件大小,但这似乎在 API 中不可用。有没有办法发送一些请求标头来获取文件大小?
额外信息:我正在使用 Python 和httplib2.Http()来处理我的HEAD请求(很高兴使用 requests 模块或任何其他替代方案)。
这是从 API 检索到的信息,该视频文件略高于 100MB(绝对不是 30k):
{
"id": "XYZ",
"productUrl": "https://photos.google.com/lr/photo/XYZ",
"baseUrl": "https://lh3.googleusercontent.com/lr/ABC",
"mimeType": "video/mp4",
"mediaMetadata": {
"creationTime": "2018-11-27T03:43:27Z",
"width": "1920",
"height": "1080",
"video": {
"fps": 120,
"status": "READY"
}
},
"filename": "VID_20181126_174327.mp4"
}
Run Code Online (Sandbox Code Playgroud)
HEAD这些是从请求接收到的标头baseUrl:
{ …Run Code Online (Sandbox Code Playgroud) python video-streaming http-headers google-photos google-photos-api
是否有一种相当直接的方法来确定远程文件的文件大小而不下载整个文件?Stack Overflow回答了如何用PHP和curl做到这一点,所以我想在R中也可以.如果可能,我认为最好避免RCurl,因为这需要为非Windows用户额外安装?
在这个调查分析网站上,我写了很多脚本来自动下载政府机构(如美国人口普查局和cdc)的大数据文件.我试图通过创建"下载缓存" 来实现一个不会下载已经下载的文件的附加组件- 但我担心如果出现以下情况,这个"下载缓存"可能会被破坏:1)主机网站更改了文件或2)用户在中途取消下载.因此,在决定是从源HTTP或FTP站点下载文件时,我想将本地文件大小与远程文件大小进行比较.如果它们不相同,请再次下载该文件.
目前我有一个如下的脚本:
<?php
$filename = "http://someurl.com/file.ext";
header('Content-Type: application/octet-stream');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$filename);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 500);
$data=curl_exec($ch);
curl_close($ch);
echo $data;
?>
Run Code Online (Sandbox Code Playgroud)
问题是服务器只是在下载整个文件后发送响应.我想让它像"流"一样工作,在下载文件时发送数据块作为响应.
用PHP和cURL可以实现吗?
我正在使用此代码在 php 中获取图像大小,它非常适合我。
$img = get_headers("http://ultoo.com/img_single.php", 1);
$size = $img["Content-Length"];
echo $size;
Run Code Online (Sandbox Code Playgroud)
但是如何通过 CURL 获得它?我试过这个,但不起作用。
$url = 'http://ultoo.com/img_single.php';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, "Content-Length" );
//curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
$filesize = $result["Content-Length"];
curl_close($ch);
echo $filesize;
Run Code Online (Sandbox Code Playgroud) 我经营一个独立的音乐网站。我们有一个巨大的 MP3 文件存储库,存储在我们的 Amazon S3 CDN 上。我们从不关心在上传时将音频的持续时间存储在数据库中。
现在,我需要以分钟和秒为单位的每个文件的长度。我不确定是否在所有文件中都设置了 TLEN ID3 信息,但我知道所有文件的比特率都是 128kbps。
由于我知道mp3的数量非常多,我不想下载整个文件来计算其音频长度。我想知道是否有更聪明的方法来做到这一点。
我正试图从远程URL获取图像的文件大小,我正试图像这样:
$remoteUrl = $file->guid;
//remote url example: http://myApp/wp-content/uploads/2017/05/Screen-Shot-2017-05-08-at-10.35.54.png
$fileSize = filesize($remoteUrl);
Run Code Online (Sandbox Code Playgroud)
但是,我得到:
filesize():http://myApp/wp-content/uploads/2017/05/Screen-Shot-2017-05-08-at-10.35.54.png的统计信息失败
如何确保文件存在于服务器上并在 URL 上找出其大小,而无需先下载文件
$url = 'http://site.zz/file.jpg';
file_exists($url); //always is false
filesize($url); //not working
Run Code Online (Sandbox Code Playgroud)
请帮助任何一个有效的例子
我正在尝试使用
get_headers($url)
Run Code Online (Sandbox Code Playgroud)
但是我得到了警告
get_headers() [function.get-headers]: http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in
Run Code Online (Sandbox Code Playgroud)
有没有其他方法可以这样做?
谢谢.
我有一个文件上传脚本在我的服务器上运行,它还具有远程上传功能..一切正常但我想知道什么是通过URL上传的最佳方式.现在我正在使用fopen从名为"from"的文本框中粘贴的远程URL获取文件.我听说fopen不是最好的方法.这是为什么?
我还使用file_get_contents从URL获取文件的文件大小.我听说那curl部分更好.为什么这样,以及如何将这些更改应用于此脚本?
<?php
$from = htmlspecialchars(trim($_POST['from']));
if ($from != "") {
$file = file_get_contents($from);
$filesize = strlen($file);
while (!feof($file)) {
$move = "./uploads/" . $rand2;
move_upload($_FILES['from']['tmp_name'], $move);
$newfile = fopen("./uploads/" . $rand2, "wb");
file_put_contents($newfile, $file);
}
}
?>
Run Code Online (Sandbox Code Playgroud) php ×10
curl ×4
duration ×1
file-upload ×1
filetime ×1
http-headers ×1
image ×1
image-size ×1
laravel ×1
mp3 ×1
performance ×1
proxy ×1
python ×1
r ×1
stream ×1