Jump to content

[SOLVED] Writing IP out to logfile --> doesn't work


phillips321

Recommended Posts

Hi guys,

 

I have a website where people have the option to upload pics.

when someone uploads a pic i want a file that logs the pic number and the remote ip.

It works so far but i cant get each new log on a new line "/n" doesnt work?

 

any ideas?

 

Here's the part where im trying to write out to the file:

$ip= $_SERVER['REMOTE_ADDR']; //remote IP address
$logoutput = "/n".$newcountnum."-->".$ip; //new data for log file
$logfile = fopen($logpath, a); //open log file in append mode
fwrite($logfile, $logoutput); //add new data to log file
fclose($logfile); //close log file

 

for some reason this code doesn't work, any ideas?

 

thanks in advance

 

And for reference here's the entire of the code:

<html>
<head>
<title>ForumPix Uploader</title>
<SCRIPT TYPE="text/javascript">
<!--
function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=440,height=365,scrollbars=no');
return false;
}
//-->
</SCRIPT>
</head>
<body background="background.gif" TEXT="#FFFFFF" LINK="FF6600" VLINK="FF6600"> <!--Changed theme to personalise-->
<center>
<A HREF="http://www.forumpix.co.uk" STYLE="text-decoration: none"><B>
<PRE>
  __                                 _                                  _    
/ _|                               (_)                                | |   
| |_ ___  _ __ _   _ _ __ ___  _ __  ___  __       ___ ___        _   _| | __
|  _/ _ \| '__| | | | '_ ` _ \| '_ \| \ \/ /      / __/ _ \      | | | | |/ /
| || (_) | |  | |_| | | | | | | |_) | |>  <   _  | (_| (_) |  _  | |_| |   < 
|_| \___/|_|   \__,_|_| |_| |_| .__/|_/_/\_\ (_)  \___\___/  (_)  \__,_|_|\_\
                              | |                                            
                              |_|                                            
</PRE>
</B></A>
<form enctype="multipart/form-data" method="POST">
        <input type="hidden" name="MAX_FILE_SIZE" value="4096000"/>
        Your file:<input name="upload" type="file">
        <font size="1">
                <A HREF="TandCs.html" onClick="return popup(this, 'notes')">Accept T&Cs:</A>
        </font>
        <input type="checkbox" name="tac" value="1" />
        <input type="submit" value="Upload!">
</form>
<?php


$countpath = 'upcount.txt'; //sets location of counter file
$logpath = 'log.txt'; //sets location of the log file
$resize = '1000'; //sets max width or height of image
$url = 'http://forumpix.getmyip.com'; //url of site (dont not include trainling "/")
$overlay = 'overlay.png';
$quality = '60'; //user sets quality of jpg image

$fail = '0';
$img_resized = '0';

$size = $_FILES['upload']['size'];
$type = $_FILES['upload']['type'];
$name = $_FILES['upload']['tmp_name'];
if ($_POST['tac'] == 1){$tac = 1;} else {$tac = 0;}

if ($name != UPLOAD_ERR_OK){$fail = 'Error uploading file!';} //checks for upload error
if ($size == 0){$fail = 'Error: uploaded file is empty!';} //file size check
if ($size > '4096000') {$fail = 'File was too big - please upload one smaller than 1MB.';} //checks uploaded file size
if ($tac == 0){$fail = 'Please acccept the terms and conditions';}

if($fail == '0'){
        //echo '<BR>FILE Type Check running';
        if ($type == 'image/jpeg') {$img = imagecreatefromjpeg($name);}  //the follwoing segment of code checks the file type
        elseif ($type == 'image/gif') {$img = imagecreatefromgif($name);}
        elseif ($type == 'image/png') {$img = imagecreatefrompng($name);}
        elseif ($type == 'image/bmp') {$img = imagecreatefromwbmp($name);}
        else {$fail = 'incorrect file type, please upload either; JPG, BMP, GIF or PNG';}
}

//echo '<BR>size='.$size;
//echo '<BR>type='.$type;
//echo '<BR>name='.$name;
//echo '<BR>tac='.$tac;

if ($fail != '0'){}
else {
        //echo '<BR>fail=PASS'; //TEMP marker to inform that fail=0

        $iwidth = imagesx($img); //get image width
        $iheight = imagesy($img); //get image height
        //echo '<BR>Image dimentions:'.$iwidth.'x'.$iheight; //show dimentions before resize

        //Shrink image size if larger than 1000x1000
        if($iwidth>$resize || $iheight>$resize){
                $img_resized = '1';
	if($iwidth>$iheight){
               		$tmp_iwidth= $resize; //set width of new size
                	$tmp_iheight = $iheight * ($tmp_iwidth/$iwidth); //create height based on width maintaining aspect ratio
	}
	else{
		$tmp_iheight= $resize; //set width of new size
        	        $tmp_iwidth = $iwidth * ($tmp_iheight/$iheight); //create width based on height maintaining aspect ratio
	}
                $tmp_resized = imagecreatetruecolor($tmp_iwidth, $tmp_iheight); //create new images with resized dimentions
                imagecopyresampled($tmp_resized, $img, 0, 0, 0, 0, $tmp_iwidth,$tmp_iheight, $iwidth, $iheight); //resample image to new size
                $img = $tmp_resized; //set resampled image back to $img
                $iwidth= imagesx($img); //get image width
                $iheight= imagesy($img); //get image height
        }


        imagealphablending($img, true); //turn on transparency on image

        $overlay = imagecreatefrompng($overlay); //create overlay image using user set file
        $owidth = imagesx($overlay); //get width of overlay image
        $oheight = imagesy($overlay); //get height of overlay image
        imagecopy($img, $overlay, $iwidth - $owidth, $iheight - $oheight, 0, 0, $owidth, $oheight); //apply overlay to image
        imagedestroy($overlay); //Get rid of temporary overlay file...

        $countfile = fopen($countpath, r); //open counter file
        $countnum = fread($countfile, filesize($countpath)); //get current counter integer
        fclose($countfile); //close counter file
        $newcountnum = $countnum + 1; //increment counter by one

        $path = 'uploads/'.str_pad($newcountnum,8,0,'STR_PAD_LEFT').'.jpg'; //create a new filename
        $webpath = $url.'/'.$path; //generate path to new photo
        
        

        if(!imagejpeg($img, $path, $quality)) {
                $fail = 'Unable to write a new JPEG. Contact the administrator.';
                echo $fail;
        }
        else {
                $countfile = fopen($countpath, w); //open counter in overwrite mode
                fwrite($countfile, $newcountnum); //write new counter num
                fclose($countfile); //close overwritten counter file
                $success=1; //success!
                
                $ip= $_SERVER['REMOTE_ADDR']; //remote IP address
                $logoutput = "/n".$newcountnum."-->".$ip; //new data for log file
                $logfile = fopen($countpath, a); //open log file in append mode
                fwrite($logfile, $logoutput); //add new data to log file
	fclose($logfile); //close log file
        }
        imagedestroy($img); //Get rid of our temporary file...
        //echo '<BR>Fail Status at end of image processing='.$fail;
}

if (!$fail=='0') { //failure during script so output UPLOAD FAILED
        echo '<font size="6">File Upload...</font>';
        echo '<BR>'.$fail;
        echo '<BR>Try to upload a file using the above form<BR>';
}
else{
        echo '<font size="6">Upload Sucess!</font><BR>';
        echo 'Your photo\'s has been uploaded to:<BR><A href='.$webpath.'>'.$webpath.'</A><BR>';
echo '<font size ="1">Copy and paste the above link into your forum when writitng a message</font><BR>';
echo 'You should see a preview of it below:<BR>';
        echo '<img src='.$webpath.' width=450><BR>';
        if ($img_resized = '1'){echo '<font size="1">Image size='.$iwidth.'x'.$iheight.'</font><BR>';} //show new dimentions
        echo 'Now feel free to upload another if you\'d like...<BR>';
}
?>
<font size="1">
<A HREF="help.html" onClick="return popup(this, 'notes')">Click here for some help</A>
</font>
</center>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.