Forum Moderators: DixonJones

Message Too Old, No Replies

Stripping out images out of logs

         

kjs50

4:32 pm on Mar 13, 2003 (gmt 0)

10+ Year Member



Hello,

My isp provides raw logs but the images are in there. I'd like to remove them at the server level before I download them. I'm on a Windows host. Does anyone have any asp or php scripts that can achieve this. Ideally copy the file to a temp file first and then strip out any image extensions.

Thanks

jatar_k

5:36 am on Mar 14, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



hmm, the easy way would be to read it line by line and dump any lines that match .jpg or .gif and write any that don't to a new, smaller file.

It wouldn't be the fastest if the logfiles are fairly large though. You could use something as simple as

$logpath = "/path/to/file.log";
$fp1 = fopen($logpath,"r");
$newpath = "/path/to/newfile.log";
$fp2 = fopen($newpath,"w");

while (!feof ($fp1)) {
$line = fgets($fp1);
if (strstr(line,"jpg") $$ strstr(line,"gif")) {
fwrite($fp2,$line);
}
}
fclose ($fp1);
fclose ($fp2);

should work though I didn't test it, as I said it may be slow for large files.

kjs50

5:26 pm on Mar 15, 2003 (gmt 0)

10+ Year Member



Thank for the code.

I'll try it out and see how it goes.

jatar_k

5:27 pm on Mar 15, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



just noticed a stupid mistake, this

if (strstr(line,"jpg") $$ strstr(line,"gif")) {

should be more like

$test1 = strstr(line,"jpg")
$test2 = strstr(line,"gif")
if ($test1 == false && $test2 == false) {