Im running a script behind a directory with a HTACCESS file and am pulling this error with getimagesize()

failed to open stream: HTTP request failed! HTTP/1.1 401 Authorization Required

ive been told i can use CURL but havent been able to find an example to use... can anyone help?

    Is the directory the image is coming from on the same server as the script?

      the images are stored in a database and are accessed via a url:

      index.php?act=view&iid=2

      there is only one page for the entire script and it refers to itself to retreive the images as indicated above

        I've tried this:

        function remote_filesize ($url, $user='web', $pass='user') {
           $ch = curl_init($url);
           curl_setopt($ch, CURLOPT_HEADER, 1);
           curl_setopt($ch, CURLOPT_NOBODY, 1);
           if (!empty($user) && !empty($pw))
           {
               curl_setopt($ch, CURLOPT_USERPWD, "$user.':'.$pw");
           }
           $okay = curl_exec($ch);
           curl_close($ch);
           return getimagesize($url);
        } 

        but i get:

        HTTP/1.1 401 Authorization Required Date: Mon, 25 Jul 2005 05:01:38 GMT Server: Apache/2.0.49 (Win32) PHP/5.0.3 WWW-Authenticate: Basic realm="Login" Content-Type: text/html; charset=iso-8859-1
        failed to open stream: HTTP request failed! HTTP/1.1 401 Authorization Required

          if the images are on your local server, specify the absolute path to them in the getimagesize function. i.e.
          $info = getimagesize("/full/path/to/image.ext");
          as opposed to
          $info = getimagesize("http://www.site.com/image.ext");

          if its on a remote server, you will need to use a method that supports http auth, such as curl.
          you use a curl session as normal and add a line
          curl_setopt($ch, CURLOPT_USERPWD, "username:password");
          and it will send the username and password with the request to get the image.
          you will then have to save it locally from the binary data and then call getimagesize and then delete the file.

            there is no image.ext.... its all done via DB

            when you call this:

            index.php?act=view&iid=2

            it pulls the image from the DB and displays it via headers.. there is no actual file or filename for any of the images

            should also add this is all happening on MY webserver

              so then where is getimagesize coming into play, that cant be used to get info from an image in a database.

                sure does, when not behind a protected directory:

                $size = getimagesize("http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?act=view&iid=".$row["image_id"]);

                works just fine.. but when within a protected directory, the proper authentication isnt sent correctly... this is wher curl would come into play but i havent gotten that to work yet

                this:

                 function remote_filesize ($url, $user='web', $pass='user') {
                   $ch = curl_init($url);
                   curl_setopt($ch, CURLOPT_HEADER, 1);
                   curl_setopt($ch, CURLOPT_NOBODY, 1);
                   if (!empty($user) && !empty($pw))
                   {
                       curl_setopt($ch, CURLOPT_USERPWD, "$user.':'.$pw");
                   }
                   $okay = curl_exec($ch);
                   curl_close($ch);
                   return getimagesize($url);
                }
                
                $size = remote_filesize("http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?act=view&iid=".$row["image_id"]);
                

                still returns authentication errors

                  curl_setopt($ch, CURLOPT_USERPWD, "$user.':'.$pw");
                  should be
                  curl_setopt($ch, CURLOPT_USERPWD, "$user:$pw");

                  but you will still get an error because using curl above
                  return getimagesize($url);
                  has no effect on getimagesize. it will still try to make its own http request for it.

                     function remote_filesize ($url, $user='web', $pass='user') {
                       $ch = curl_init($url);
                       curl_setopt($ch, CURLOPT_HEADER, 0);
                       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                       curl_setopt($ch, CURLOPT_USERPWD, "$user:$pass");
                    
                       $data = curl_exec($ch);
                       curl_close($ch);
                    
                       $filename = "temp." . time();
                    
                       $fp = @fopen($filename, "w+");
                       fwrite($fp, $data);
                       fclose($fp);
                    
                       $info = getimagesize($filename);
                    
                       @unlink($filename);
                    
                       return $info;
                    }
                    
                    $size = remote_filesize("http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?act=view&iid=".$row["image_id"]);
                    
                      Write a Reply...