Re: [PHP3] Download a file // IF question // Read a file!
| From: | (Richard Lynch) | Date: | Wed, 21 Jun 2000 00:01:43 +0000 |
| Subject: | Re: [PHP3] Download a file // IF question // Read a file! | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-2404@lists.php.net to get a copy of this message | ||
In article <014c01bfd774$258dee60$cf1013c2@sune311>, sune@drs.no ("Sune
Alexandersen") wrote:
> 1. I¨d like to be able to click a link, and instead of opening the file
> in the browser, to be able to download it. How can this be done?
Search the archives for "octet-stream" and do all the headers you can find
to make it work. Be careful -- different browsers are following different
"standards".
> 2. I write an IF like this:
> IF(condition)
> { this thing }
> elseif(condition 2)
> { this thing }
> else(condition 3)
> { the other thing }
> But I bet my mums socks it can be done otherwise.. How about something like
>
> IF(condition) OR (condition 2)
> { this thing }
> else(condition 3)
> { the other thing }
>
> how would I accomplish that?
if (condition OR condition2)
{ this thing }
eiseif (condition3)
{ the other thing}
> 3. I would like to read the contents of a text file on a remote server
> and compare to a value. This is to check to see if there is any update of my
> program. Lets say I have a file called www.someserver.com/updates.txt
> containing only the digit 2.1 .. I would like the script to compare 2.1 with
> the current version and to echo UPDATE AVAILABLE if the number is greater.
> Ive tried with
>
> // get contents of a file into a string
> $filename = "/usr/local/something.txt";
> $fd = fopen ($filename, "r");
> $contents = fread ($fd, filesize ($filename));
> fclose ($fd);
$filename = fopen("http://www.someserver.com/updates.txt",
'r') or
die("remove fiel not accessible.");
> as mentioned in the online manual, but I only succeed in opening a local
> file.. And how can i compare a number with a decimal?
PHP will take care of that for you for a single decimal:
if ($remote_version > $local_version){
echo "Update Available";
}
However, version numbers with multiple decimal points is another matter
entirely... So if you need 2.1.1 to work, you'll have to write a custom
comparison function...
function versioncmp($version1, $version2){
//Returns 0 if two versions are equal.
//Returns -1 if $version1 is less than $version2
//Returns 1 if $version1 is greater than $version2
//See strcmp
//NOTE: Does not handle "Beta", "RC", or any other non-numeric version
//designation.
$parts1 = explode('.', $version1);
$parts2 = explode('.', $version2);
$result = 0;
while (!$result && list(,$v1) = each($parts1) && list(,$v2) = each($parts2)){
if ($v1 < $v2){
$result = -1;
}
elseif ($v1 > $v2){
$result = 1;
}
}
return $result;
}
--
Richard Lynch | If this was worth $$$ to you, buy a CD
US Customer Support Director | from one of the artists listed here:
Zend Technologies USA | http://www.L-I-E.com/artists.htm
http://www.zend.com | (this has nothing to do with Zend,
duh!)