Okay, just playing around with this and I'm wondering how you go about getting the runtime of the image in KB? Here's the little snippet I'm using:

<?php
$blah = getimagesize("http://www.somesite.com/someimage.jpg");
$type = $blah['mime'];
$width = $blah[0];
$height = $blah[1];
echo "Type = $type <br>";
echo "Width = $width <br>";
echo "Height = $height <br>";
?>

    Ummm..."runtime"? Not sure what you mean by that in relation to an image file. 😕

      NogDog;10883790 wrote:

      Ummm..."runtime"? Not sure what you mean by that in relation to an image file. 😕

      Runtime, meaning size of the actual image file (or any file for that matter). Bytes, KB, MB, GB, etc. 🙂

        PallinWolf wrote:

        Runtime, meaning size of the actual image file (or any file for that matter). Bytes, KB, MB, GB, etc.

        'When I use a word,' Humpty Dumpty said in a rather scornful tone, 'it means just what I choose it to mean - neither more nor less.'

          don't forget that filesize() will return the filesize in B (bytes), so you will need to use some sort of function to convert it to kB, MB, etc.

            For all the smarty pants with the "manual" comments - I am well aware of it but filesize wasn't working for me. I thought there might be another way so that's why I posted here.

            However, I found a work around for it and I have what I needed now.

              Would you mind sharing the solution that you are using, in order that other people with a similar problem might benefit from it?

                PallinWolf wrote:

                For all the smarty pants with the "manual" comments - I am well aware of it but filesize wasn't working for me.

                Then you should have said so in the first place: how are we supposed to know what you've already tried if you don't tell us?

                filesize() wouldn't have worked because you're not giving it a filename, but a URL. If you don't want to send a HEAD request yourself and hope for a Content-Length header, you have to request the file from the other server and look at the size of what you get back.

                  filesize() wouldn't have worked because you're not giving it a filename, but a URL. If you don't want to send a HEAD request yourself and hope for a Content-Length header, you have to request the file from the other server and look at the size of what you get back.

                  Then why didn't you say that on your first post, rather than just slapping in some smartass comment? Anyone that wants to just tell people "zomg use the manual!!11one" just shouldn't bother cluttering these boards, imo. Go act cool somewhere else.

                    Ashley Sheridan;10883896 wrote:

                    Would you mind sharing the solution that you are using, in order that other people with a similar problem might benefit from it?

                    Sure thing. Here is the method I'm using to get the actual filesize of an image URL:

                    <?php
                    $filename = "http://www.somesite.com/someimage.jpg";
                    $fh = fopen($filename, "r");
                    while(($str = fread($fh, 1024)) != null) $fsize += strlen($str);
                    echo "File size: ".$fsize;
                    ?>
                    
                      PallinWolf;10883941 wrote:

                      Then why didn't you say that on your first post, rather than just slapping in some smartass comment? Anyone that wants to just tell people "zomg use the manual!!11one" just shouldn't bother cluttering these boards, imo. Go act cool somewhere else.

                      I was planning to, once I realised that since you were using a URL in getimagesize() you would probably try using it in filesize() as well (assuming you hadn't tried already) as well, but somehow I slipped and saved the post without it. My apologies. But where did you get "runtime" from?

                      use the manual

                      In my opinion, the people who shouldn't be cluttering the boards are those who don't bother to even look at the manual, and just blurt out here every single question that crosses their minds. I'm not saying that you're one of them, but there are enough.

                      Gaahh... did it again. Flipped through the tabs and found this textarea. Now, what was I thinking?

                      Oh, yes; you could probably shorten that code to strlen(get_file_contents("http://www.example.com/image.png")).

                      Better yet, since you actually want the file, seeing as you're after its dimensions (and maybe other things) as well, use get_file_contents() and save the result locally to a tmpfile, then use filesize() and getimagesize() on that. Saves you requesting and downloading it twice.

                        But where did you get "runtime" from?

                        It's just a term myself and a lot of former co-workers started using years ago. It doesn't actually mean anything, I know, but I slipped when I made this thread and when it wasn't understood I tried to explain better what I meant.

                        Any yes, I agree that almost ALL coding help boards have the problem with everyone just blurting a request out, but I assure you that I'm not one of them. I was just playing with that little image retrieval snippet and I realized that filesize() wasn't going to be the way to get what I needed. Then, I went through the manual and didn't really see anything that jumped out at me so I figured I'd ask here for anyone that had a method already in use.

                        The idea was to check the image for its dimensions and size (bytes, KB, whatever) and only allow it to be displayed if it met the already established maximum allowable sizes. It's for my chat system.

                        Oh, yes; you could probably shorten that code to strlen(get_file_contents("http://www.example.com/image.png")).

                        Better yet, since you actually want the file, seeing as you're after its dimensions (and maybe other things) as well, use get_file_contents() and save the result locally to a tmpfile, then use filesize() and getimagesize() on that. Saves you requesting and downloading it twice.

                        Thanks for that idea, I'll play around with it!

                          Write a Reply...