getting image width/height before uploading

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ok

    getting image width/height before uploading

    Hello,

    Q: How do I get image width and height before uploading an image?
    This because, I want to restrict people uploading huge files.


    Thanks in advance

  • Justin Koivisto

    #2
    Re: getting image width/height before uploading

    ok wrote:[color=blue]
    > Hello,
    >
    > Q: How do I get image width and height before uploading an image?
    > This because, I want to restrict people uploading huge files.[/color]

    You can't with PHP. You'd have to get some kind of javascript to do it
    since it would be client-side _before_ uploading. However, I usually
    handle it by uploading the file, then using GD to resize it
    appropriately. The only restriction you'd set then is the max file size
    to upload.

    --
    Justin Koivisto - spam@koivi.com
    PHP POSTERS: Please use comp.lang.php for PHP related questions,
    alt.php* groups are not recommended.

    Comment

    • Paul Wellner Bou

      #3
      Re: getting image width/height before uploading

      Hi,

      Afaik there is no way to get the image (or any other file)-data
      such as size, height, length etc with php before uploading.
      PHP is executed on the server, so it has no rights to access
      files on the client machine.
      You have two possibilities, you can load the image in your page
      from the client and check the height and width with javascript,
      what i don't recommend, because javascript depends on the browser
      software of the client.
      The second is to upload the file anyway (which will be loaded into
      a temp-directory), check it then, and if ok, you can save it where
      you want to save it on the server.
      To avoid that any user uploads a image whichis really too big, you
      have the server or php.ini configurations to set the max_file_size
      or a timeout of the script.

      Greetz
      Paul.

      Comment

      • sk

        #4
        Re: getting image width/height before uploading

        This is probably the way to go, though now that the file is on your
        server for poking and prodding, you can use the same image functions to
        resize it down to your preferred maximum size and maybe convert it (if
        they uploaded a BMP or a GIF and you just want JPEGs or PNGs) to a
        uniform format.

        --
        Steve Koppelman



        Paul Wellner Bou wrote:
        ....[color=blue]
        > The second is to upload the file anyway (which will be loaded into
        > a temp-directory), check it then, and if ok, you can save it where
        > you want to save it on the server.
        > To avoid that any user uploads a image whichis really too big, you
        > have the server or php.ini configurations to set the max_file_size
        > or a timeout of the script.
        >
        > Greetz
        > Paul.[/color]

        Comment

        • Justin Koivisto

          #5
          Re: getting image width/height before uploading

          sk TOP-POSTED when he wrote:
          [color=blue]
          > Paul Wellner Bou wrote:
          > ...
          >[color=green]
          >> The second is to upload the file anyway (which will be loaded into
          >> a temp-directory), check it then, and if ok, you can save it where
          >> you want to save it on the server.
          >> To avoid that any user uploads a image whichis really too big, you
          >> have the server or php.ini configurations to set the max_file_size
          >> or a timeout of the script.
          >>[/color]
          >
          > This is probably the way to go, though now that the file is on your
          > server for poking and prodding, you can use the same image functions to
          > resize it down to your preferred maximum size and maybe convert it (if
          > they uploaded a BMP or a GIF and you just want JPEGs or PNGs) to a
          > uniform format.
          >[/color]

          Maybe it's just me, but isn't that what I had said in the first place?
          Maybe nobody is getting/reading my messages?

          --
          Justin Koivisto - spam@koivi.com
          PHP POSTERS: Please use comp.lang.php for PHP related questions,
          alt.php* groups are not recommended.

          Comment

          • Matty

            #6
            Re: getting image width/height before uploading

            Justin Koivisto wrote:
            [color=blue]
            > sk TOP-POSTED when he wrote:
            >[color=green]
            >> Paul Wellner Bou wrote:
            >> ...
            >>[color=darkred]
            >>> The second is to upload the file anyway (which will be loaded into
            >>> a temp-directory), check it then, and if ok, you can save it where
            >>> you want to save it on the server.
            >>> To avoid that any user uploads a image whichis really too big, you
            >>> have the server or php.ini configurations to set the max_file_size
            >>> or a timeout of the script.
            >>>[/color]
            >>
            >> This is probably the way to go, though now that the file is on your
            >> server for poking and prodding, you can use the same image functions to
            >> resize it down to your preferred maximum size and maybe convert it (if
            >> they uploaded a BMP or a GIF and you just want JPEGs or PNGs) to a
            >> uniform format.
            >>[/color]
            >
            > Maybe it's just me, but isn't that what I had said in the first place?
            > Maybe nobody is getting/reading my messages?
            >[/color]

            Or maybe, just maybe, you could let them upload the file first, THEN decide
            if it's too big, etc....

            ;p <grin>

            Don't know if anyone has pointed this out yet, but
            1 - you can set the max size for an uploaded file in php.ini
            2 - although it may/may not be supported by the browser, you can set

            Comment

            Working...