Copying .gif from server to hd
Posted: Sat Dec 06, 2003 2:28 pm
Hey,
I am attempting to use the following script to download a gif from a server, then put it into a local file, but when I view the local version of the gif it is all "scrambled."
My Code:
The reason I split the filename up so much is because there are about 8 dirs, numberd 01 - 08, each dir contains a certain number of files with a number inside the filename that grows larger, and I would eventually like to loop through all dirs and all .gifs in the dirs and save them.
Any ideas on what is going on and how to fix it?
I am attempting to use the following script to download a gif from a server, then put it into a local file, but when I view the local version of the gif it is all "scrambled."
My Code:
Code: Select all
<?php
$newPath = "LOCALPATHHERE";
$url = "URLHERE";
$fileDir = "01/";
$filePre = "ch";
$fileMid = 920101;
$filePost = ".gif";
for ( ; $fileMid <= 920105; $fileMid++)
{
$newFile = $newPath . $filePre . $fileMid . $filePost;
$getFile = $url . $fileDir . $filePre . $fileMid . $filePost;
$fp1 = fopen($getFile, "r") or die ("Couldn't open $getFile.");
$fp2 = fopen($newFile, "w") or die ("Couldn't open $newFile.");
while (!feof($fp1)) { fwrite($fp2, fgets($fp1, 1024)); }
fclose($fp1);
fclose($fp2);
}
?>Any ideas on what is going on and how to fix it?