Jump to content

Checking online files


Recommended Posts

Hi, I need to use an icon from the internet, typically it's www.webaddress.com/favico.ico, but obviously that doesn't always exist, and I find that when it doesn't my script gets all hung up there. Right now, I'm just saving each favicon to the temp dir, then using it from there, but like I said, there's no checking before using InetGet() so it can freeze up my program. I know FileExists() doesn't work, what's the best way to do this? Is there a way to display an icon without downloading it? If not, how should I download it without lags? Thanks

Link to comment
Share on other sites

Hi, I need to use an icon from the internet, typically it's www.webaddress.com/favico.ico, but obviously that doesn't always exist, and I find that when it doesn't my script gets all hung up there. Right now, I'm just saving each favicon to the temp dir, then using it from there, but like I said, there's no checking before using InetGet() so it can freeze up my program. I know FileExists() doesn't work, what's the best way to do this? Is there a way to display an icon without downloading it? If not, how should I download it without lags? Thanks

This could help you, doesn't seem to lag that much. It's just a good method to find if the file exists. If it does not, gives an error, if it does, gives a mesage. Just adapt it to what you need:

$size = 0
$goodURL = "http://www.google.com/intl/en_ALL/images/logo.gif"
Test($goodURL)
$badURL = "http://somedomain.com/file.exe"
test($badURL)

Func test($url = "")
    $start = TimerInit()
    $size = InetGetSize($url)
    If $size = 0 Then 
        $end = TimerDiff($start)/1000
        MsgBox(0, "Error on: "&$url, "File doesn't exist, took: "&$end&"s to find that out.")
    Else
                $end = TimerDiff($start)/1000
        MsgBox(0, "Worked: "&$url, "File exists, took: "&$end&"s to find the size of: "&$size)
    EndIf
EndFunc

The function there is just to let you know how long it took to either succeed or fail. You could easily adapt that to test if your ico file exists online, and if it does, download it, and use it, or if it does not, use a cached version of it.

Edited by zackrspv

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

Thanks! That really helped!

Ahh!

Hmmm, it worked great in your example, but when trying to get a file from Digg, it lags for ~20 second before returning a size of 0.... Also it can't find the favicon there even though this address exists... Can anyone else verify either of these problems?

iconExists("http://www.digg.com/favicon.ico")

Func iconExists($url)
    $start = TimerInit()
    $size = InetGetSize($url)
    If $size == 0 Then
        MsgBox(0, "", @CRLF & "Failed " & " in " & TimerDiff($start) / 1000)
        Return False
    Else
        MsgBox(0, "", @CRLF & "Loaded " & " in " & TimerDiff($start) / 1000)
        Return True
    EndIf
EndFunc
Edited by magician13134
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...