Monkuar Posted November 13, 2011 Share Posted November 13, 2011 Is there a way I can get the .jpg file in kilobytes from a remote url and check it to make sure it does not exceed 40 kilobytes before it saves the remote url into my database? Quote Link to comment https://forums.phpfreaks.com/topic/251055-getting-image-size-with-no-upload/ Share on other sites More sharing options...
RussellReal Posted November 14, 2011 Share Posted November 14, 2011 maybe in internet explorer (with VBScript) but for the most part.. JavaScript is very limited in what it can do with the hosting computer.. Quote Link to comment https://forums.phpfreaks.com/topic/251055-getting-image-size-with-no-upload/#findComment-1287897 Share on other sites More sharing options...
shlumph Posted November 14, 2011 Share Posted November 14, 2011 Here's kind of a hack way to do it. There might be a better way: $content = file_get_contents("http://www.example.com/path/to/image.jpg"); $handle = fopen("image.jpg", "w+"); fwrite($handle, $content); fclose($handle); $size = filesize('image.jpg'); In short, you are probably going to have to download the file, at least temporarily, to get the file size. You can always delete it right after. Quote Link to comment https://forums.phpfreaks.com/topic/251055-getting-image-size-with-no-upload/#findComment-1287903 Share on other sites More sharing options...
kicken Posted November 14, 2011 Share Posted November 14, 2011 You can try doing a HEAD request with get_headers() and then find the Content-Length: header. If that fails you can fall back to a file_get_contents/strlen() combo to get the size. Quote Link to comment https://forums.phpfreaks.com/topic/251055-getting-image-size-with-no-upload/#findComment-1287910 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.