Jump to content


Photo

Requesting help, logging IPs using flat file


  • Please log in to reply
4 replies to this topic

#1 PHP6

PHP6
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 07 October 2006 - 05:38 PM

I have an image uploading site that a small private community uses, and lately some imature people have been uploading some explicit pictures... I was wondering if anyone could help me improve my current uploading script so that it logged the IP along with the corresponding direct image link of what they uploaded, and then save it to a txt file.

Current code:

<form action="result.php" method="post" name="form1" enctype="multipart/form-data">
<input class="file" name="userfile" type="file">
<input type="hidden" name="MAX_FILE_SIZE" value="300000" />
<input class="button" value="Upload" name="action" id="uploadit" type="submit">
</form>

result.php:

<?php

                        $yoursite = "http://removed";        
                        $uploaddir = "./imageuploads/";
                        $uploadfile = $uploaddir . basename(str_replace(" ", "", $_FILES['userfile']['name']));

                        $ext = explode(".", $_FILES['userfile']['name']);
                        $ext = array_pop($ext);
                        $ext = strtolower($ext);

                        $fna = explode(".", $_FILES['userfile']['name']);
                        $filename = $fna[0];
                        $origfilename = $filename;

                        $fileType = $_FILES['userfile']['type'];

                        $i = 1;


                        if ($ext == "jpeg" || $ext == "png" || $ext == "jpg" || $ext == "gif")
                            {
                            if ($fileType == "image/gif" || $fileType == "image/pjpeg" || $fileType == "image/x-png" || $fileType == "image/jpeg" || $fileType == "image/png")
                                {
                                while (file_exists( $uploadfile )) 
                                    {
                                    $filename = $origfilename;
                                    $newfilename = $filename. $i . "." .$ext;
                                    $uploadfile = $uploaddir . $newfilename;
                                    $i++;
                                    }

                                if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
                                    {
                                    echo "<img src=".$uploadfile." width='0' height='0'>" .
                                            "<p>File uploaded <font color=green><b>successfully!</b></font>" .
                                            "<br /> " .
                                            "<br /><input type='text' onClick='select(this);' style='width: 420px' size='70' value='[url=$yoursite][img]" . $yoursite .substr($uploadfile, 1) . "[/img][/url]' /> Hotlink for forums<br />" .
                                            "<br /><input type='text' onClick='select(this);' style='width: 420px' size='70' value='<a href=" . $yoursite . "><img src=" . $yoursite .substr($uploadfile, 1) . "></a>' /> Hotlink for websites<br />" .
                                            "<br /><input type='text' onClick='select(this);' style='width: 420px' size='70' value='" . $yoursite . substr($uploadfile, 1) . "' /> Direct Link to image";
                                    } 
                                else 
                                    {
                                    echo "File <font color=red><b>failed</b></font> to upload, no upload specified or unsupported extension\n";
                                    }
                                }
                            else
                                {
                                echo "File <font color=red><b>failed</b></font> to upload, no upload specified or unsupported extension";
                                }
                            }
                        else
                            {
                            echo "File <font color=red><b>failed</b></font> to upload, no upload specified or unsupported extension";
                            }
                    ?>

I really don't know where to begin... So if anyone could help me out i'd greatly appreciate it.


#2 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 07 October 2006 - 05:41 PM

make your form:
<?php $ip = $_SERVER[REMOTE_ADDR]; ?>
<form action="result.php" method="post" name="form1" enctype="multipart/form-data">
<input class="file" name="userfile" type="file">
<input type="hidden" name="MAX_FILE_SIZE" value="300000" />
<input class="button" value="Upload" name="action" id="uploadit" type="submit">
<input type=hidden name=ip value='<?php echp $ip ?>'>
</form>
[code]

and then in the result.php add
[code]
$ip = $_POST[ip];
[/code]

then just edit your filename part and ad $ip somewheres in there[/code]


#3 PHP6

PHP6
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 07 October 2006 - 06:25 PM

make your form:

<?php $ip = $_SERVER[REMOTE_ADDR]; ?>
<form action="result.php" method="post" name="form1" enctype="multipart/form-data">
<input class="file" name="userfile" type="file">
<input type="hidden" name="MAX_FILE_SIZE" value="300000" />
<input class="button" value="Upload" name="action" id="uploadit" type="submit">
<input type=hidden name=ip value='<?php echp $ip ?>'>
</form>
[code]

and then in the result.php add
[code]
$ip = $_POST[ip];
[/code]

then just edit your filename part and ad $ip somewheres in there[/code]


Sorry, I don't know much about PHP, but doesn't that just display to the user what their IP is? I want the IPs to be saved to a text file so I can see them.

Example: log.txt

555.5.5.5.5 - http://mywebsite/ima...on1Uploaded.png
555.5.5.5.6 - http://mywebsite/ima...on2Uploaded.png

Something like that

#4 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 07 October 2006 - 07:30 PM

This should get u started, put an empty writeable file named "log.txt" in the same directory as your images
You see where i've added it and what i've added
<?php

while (file_exists( $uploadfile ))
{
$filename = $origfilename;
$newfilename = $filename. $i . "." .$ext;
$uploadfile = $uploaddir . $newfilename;

// start adding to log.txt
$logfilename = $uploaddir."/log.txt";
$time = date("F j, Y, g:i a");
$ip = $_SERVER['REMOTE_ADDR'];
$string = "$newfilename|$ip|$time\n";
$prep = fopen($logfilename, "a+");
fwrite($prep, $string);
fclose($prep);
// end logfile

$i++;
}

?>

results: new_filename|IP|date_time

#5 PHP6

PHP6
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 07 October 2006 - 08:15 PM

This should get u started, put an empty writeable file named "log.txt" in the same directory as your images
You see where i've added it and what i've added

<?php

while (file_exists( $uploadfile ))
{
$filename = $origfilename;
$newfilename = $filename. $i . "." .$ext;
$uploadfile = $uploaddir . $newfilename;

// start adding to log.txt
$logfilename = $uploaddir."/log.txt";
$time = date("F j, Y, g:i a");
$ip = $_SERVER['REMOTE_ADDR'];
$string = "$newfilename|$ip|$time\n";
$prep = fopen($logfilename, "a+");
fwrite($prep, $string);
fclose($prep);
// end logfile

$i++;
}

?>

results: new_filename|IP|date_time


That works perfect! Thankyou so much, I really appreciate it.  :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users