| Topic Archived |
View previous topic :: View next topic |
| Author |
Message |
DJ Maze Developer


Offline Joined: Apr 19, 2004 Posts: 5683 Location: http://tinyurl.com/5z8dmv
|
Posted: Thu Oct 14, 2004 5:47 pm Post subject: New function and remote avatar filesize |
|
Ok as people liked the remote avatar check for dimension (widthxheight) it still lacked the ability to check filesize (bytes)
Also Trevor is building a new downloads module and also wanted to fetch remote filesize.
So i've created a new function get_fileinfo($url)
The function recieves the first 12 lines of a url and tries to fetch the size, type and filedate from those and return them into a array()
$file['size'] in bytes
$file['type'] like: image/jpeg or application/zip
$file['date'] like: Thu, 22 Apr 2004 18:54:07 GMT
This way the avatar system now also checks the remote avatar filesize
DJ Maze's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS) Fedora 15 / 2.2.22 / 5.5.20 / 5.3.10 / CVS
|
|
| Back to top |
|
 |
Phoenix • Many Posts •


Offline Joined: Apr 19, 2004 Posts: 8799 Location: Netizen
|
Posted: Thu Oct 14, 2004 5:51 pm Post subject: Re: New function and remote avatar filesize |
|
terrific - now, if you could just detect animated gifs........
Phoenix's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
|
|
| Back to top |
|
 |
PerM Dragonfly addicted


Offline Joined: Aug 07, 2004 Posts: 390 Location: Sweden
|
Posted: Fri Oct 15, 2004 11:41 am Post subject: Re: New function and remote avatar filesize |
|
Oh, very nice indeed.
Two questions:
Will the new download module hide the real URL to prevent direct linking? I.e. provide a link to a temporary file that gets deleted when the download is completed or the temporary fils os older that x hours/minutes?
The twelve lines...is that the result form the HTTP request you are talking about?
PerM's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
|
|
| Back to top |
|
 |
PerM Dragonfly addicted


Offline Joined: Aug 07, 2004 Posts: 390 Location: Sweden
|
Posted: Fri Oct 15, 2004 11:42 am Post subject: Re: New function and remote avatar filesize |
|
| Phoenix wrote: |
| terrific - now, if you could just detect animated gifs........ |
I guess this is possbile by looking at the raw image data. I'll try to dig something up on this.
PerM's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
|
|
| Back to top |
|
 |
DJ Maze Developer


Offline Joined: Apr 19, 2004 Posts: 5683 Location: http://tinyurl.com/5z8dmv
|
Posted: Fri Oct 15, 2004 11:59 am Post subject: Re: New function and remote avatar filesize |
|
| PerM wrote: |
Oh, very nice indeed.
Two questions:
Will the new download module hide the real URL to prevent direct linking? I.e. provide a link to a temporary file that gets deleted when the download is completed or the temporary fils os older that x hours/minutes?
The twelve lines...is that the result form the HTTP request you are talking about? |
| Code:: |
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://cpgnuke.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://cpgnuke.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.cpgnuke.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.cpgnuke.com$ [NC]
RewriteRule .*\.(jpg|jpeg|png|bmp|zip|rar)$ - [F,NC] |
Yes, it does a HTTP GET request
If the request fails (ie returning something else then "HTMTL/1.x 200 OK") it returns false and throws a E_USER_WARNING error.
DJ Maze's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS) Fedora 15 / 2.2.22 / 5.5.20 / 5.3.10 / CVS
|
|
| Back to top |
|
 |
PerM Dragonfly addicted


Offline Joined: Aug 07, 2004 Posts: 390 Location: Sweden
|
Posted: Fri Oct 15, 2004 12:38 pm Post subject: Re: New function and remote avatar filesize |
|
A quick search on animimated gifs yields that it is quite easy to detect an animated gif. I haven't done any real coding in php yet, as side from a few bugfixes for CPGNuke, but I'll see what I can come up with.
PerM's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
|
|
| Back to top |
|
 |
djdevon3 Gold Supporter


Offline Joined: Aug 05, 2004 Posts: 4363
|
Posted: Fri Oct 15, 2004 7:05 pm Post subject: Re: New function and remote avatar filesize |
|
There are a two major formats of gifs. 87a and 89a. One of the two doesn't support animation I believe. They both show up in browsers as a .gif format. You guys are advanced coders so maybe this is the kind of info you could use.
www.danbbs.dk/~dino/wh...gif89.html
djdevon3's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS) Linux/1.3.33/4.4/4.3.11
|
|
| Back to top |
|
 |
DJ Maze Developer


Offline Joined: Apr 19, 2004 Posts: 5683 Location: http://tinyurl.com/5z8dmv
|
Posted: Fri Oct 15, 2004 7:37 pm Post subject: Re: New function and remote avatar filesize |
|
Devon that document doesn't descibes animation properties, only
| Quote:: |
| The Graphics Interchange Format is not intended as a platform for animation, even though it can be done in a limited way. |
And yes only 89a supports animation
DJ Maze's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS) Fedora 15 / 2.2.22 / 5.5.20 / 5.3.10 / CVS
|
|
| Back to top |
|
 |
PerM Dragonfly addicted


Offline Joined: Aug 07, 2004 Posts: 390 Location: Sweden
|
Posted: Fri Oct 15, 2004 8:10 pm Post subject: Re: New function and remote avatar filesize |
|
Yep, only 89a supports animations. It seem it'll be quite easy to determine if a gif image is animated or not. All that is needed is to search for the string "NETSCAPE2.0" in the raw data.
I've tested this on some .gif files and it seems to be accurate. Although, to be the 100% accurate it is of course needfull to actually read the data and process it -- there are 'static' animations that only show the first frame of an animation.
So if someone with better knowledge of php than me wants to write a code snippet that reads the raw .gif image data (from file and/or over the HTTP protocol), go ahead and do so. Just remember who said it first
Gif 89a Specifications
Sample of the animation structure
PerM's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
|
|
| Back to top |
|
 |
DJ Maze Developer


Offline Joined: Apr 19, 2004 Posts: 5683 Location: http://tinyurl.com/5z8dmv
|
Posted: Fri Oct 15, 2004 8:23 pm Post subject: Re: New function and remote avatar filesize |
|
| rolleyes.gif wrote: |
| removed see image below |
All data is LZW compressed so it needs to be uncompressed and check how the image "loops"
DJ Maze's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS) Fedora 15 / 2.2.22 / 5.5.20 / 5.3.10 / CVS
Last edited by DJ Maze on Fri Oct 15, 2004 10:33 pm; edited 1 time in total |
|
| Back to top |
|
 |
DJ Maze Developer


Offline Joined: Apr 19, 2004 Posts: 5683 Location: http://tinyurl.com/5z8dmv
|
Posted: Fri Oct 15, 2004 8:29 pm Post subject: Re: New function and remote avatar filesize |
|
you could ofcourse load the file fully and do
| PHP: |
if ($fileinfo = get_fileinfo($url)) { if ($fileinfo['type'] == 'image/gif') { // get whole image using fsockopen() and feof() if (ereg('NETSCAPE2.0', $file)) cpg_error('Image is animated'); } }
|
GOOD LUCK !!!
DJ Maze's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS) Fedora 15 / 2.2.22 / 5.5.20 / 5.3.10 / CVS
|
|
| Back to top |
|
 |
MrFatCat Nice poster


Offline Joined: Oct 02, 2004 Posts: 51 Location: Chattanooga, TN
|
Posted: Fri Oct 15, 2004 8:34 pm Post subject: Re: New function and remote avatar filesize |
|
I think maybe the image seperator might be key to determining if the data stream has more than one image present.
| Image Separator" wrote: |
Identifies the beginning of an Image Descriptor. This field contains the fixed value 0x2C. |
_________________ Are we having fun yet?
Home of the FatCat and My 9.0 [CPGNuke] Playground
MrFatCat's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS) Linix-Redhat 3.0 Enterprise/Apache 1.3.31/MySql 4.0.20-standard /PHP 4.3.8/CPG 8.2b (& CVS 9.0)
|
|
| Back to top |
|
 |
DJ Maze Developer


Offline Joined: Apr 19, 2004 Posts: 5683 Location: http://tinyurl.com/5z8dmv
|
Posted: Fri Oct 15, 2004 9:25 pm Post subject: Re: New function and remote avatar filesize |
|
0x2C is character "," and mostly it has 0x00 before it.
There are 9 occurences in above image and that's correct because the gif contains 9 frames
| PHP: |
preg_match('/\x00\x2C/', $file, $matches)
|
should do the trick probably
DJ Maze's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS) Fedora 15 / 2.2.22 / 5.5.20 / 5.3.10 / CVS
|
|
| Back to top |
|
 |
DJ Maze Developer


Offline Joined: Apr 19, 2004 Posts: 5683 Location: http://tinyurl.com/5z8dmv
|
Posted: Fri Oct 15, 2004 10:29 pm Post subject: Re: New function and remote avatar filesize |
|
Here's some better detail
_________________ There are two paths, the short one and the long one.
When you choose the short path you will notice it takes longer then the long path.
So READ the FAQ and Wiki first 
DJ Maze's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS) Fedora 15 / 2.2.22 / 5.5.20 / 5.3.10 / CVS
|
|
| Back to top |
|
 |
PerM Dragonfly addicted


Offline Joined: Aug 07, 2004 Posts: 390 Location: Sweden
|
Posted: Fri Oct 15, 2004 11:37 pm Post subject: Re: New function and remote avatar filesize |
|
| DJMaze wrote: |
| rolleyes.gif wrote: |
| removed see image below |
All data is LZW compressed so it needs to be uncompressed and check how the image "loops" |
The image data is compressed, not the header as I understand it...."NETSCAPE2.0" certainly isn't compressed.
PerM's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
|
|
| Back to top |
|
 |
|
|