Jump to content

Archived

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

PHP6

Requesting help, logging IPs using flat file

Recommended Posts

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:

[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>
[/code]

result.php:

[code=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";
                            }
                    ?>
[/code]

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

Share this post


Link to post
Share on other sites
make your form:
[code]
<?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][/code]

Share this post


Link to post
Share on other sites
[quote author=mgallforever link=topic=110816.msg448599#msg448599 date=1160242887]
make your form:
[code]
<?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][/code]
[/quote]

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/imageuploads/TheFilePerson1Uploaded.png
555.5.5.5.6 - http://mywebsite/imageuploads/TheFilePerson2Uploaded.png

Something like that

Share this post


Link to post
Share on other sites
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
[code]
<?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++;
}

?>
[/code]

results: new_filename|IP|date_time

Share this post


Link to post
Share on other sites
[quote author=alpine link=topic=110816.msg448646#msg448646 date=1160249406]
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
[code]
<?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++;
}

?>
[/code]

results: new_filename|IP|date_time
[/quote]

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

Share this post


Link to post
Share on other sites

×

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.