I have an image upload thingy on my site: http://www.lights4yourpc.com/pictures.html and it emails me to tell me an image has been uploaded and sends the name and comments of the person who uploaded it.
Can anyone help me to make it email me the person's IP address also, so that I can block people who upload millions of inapropriate images?
Thanks.
Joe
here is the code of the upload_file.php
and here is the code of the pictures.html page:
Can anyone help me to make it email me the person's IP address also, so that I can block people who upload millions of inapropriate images?
Thanks.
Joe
here is the code of the upload_file.php
Code:
<?php
//Email function.
function send_email($name, $comments) {
//Set vars.
$to = "upload@lights4yourpc.com";
$subject = "Image uploaded by " . $name;
$message = "An image has been uploaded, the details are below.\n\nName: " . $name . "\nComments: " . $comments . "\n\nThanks, your website";
$from = "From: <$name>";
//Send email.
mail($to, $subject, $message, $from);
}
//Check for image types.
if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 5000000) && isset($_POST['name']) && isset($_POST['comments'])) {
//Check for an error.
if ($_FILES["file"]["error"] > 0) {
//If an error, tell the user.
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
} else {
//Show upload details.
echo "Image upload successful: <br>" . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
//Check if the file exists.
if (file_exists("upload/" . $_FILES["file"]["name"])) {
//If the file exists, tell the user.
echo $_FILES["file"]["name"] . " already exists. ";
} else {
//Upload the image.
move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
//Inform the user.
echo "Stored in: " . "folder/" . $_FILES["file"]["name"];
//Send the email.
send_email($_POST['name'], $_POST['comments']);
}
}
} else {
//Tell the user file is invalid or they have left a field blank.
echo "You have either left a field blank in the form or have uploaded the wrong kind of file, please go <a href=\"pictures.html\" >back</a> and try again.";
}
?>
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>High power lights for your computer</title>
<link href="Favicon.ico" rel="SHORTCUT ICON">
<META NAME="description" CONTENT="Make your PC look cool! High power flashing LED Lights for your desktop PC."><META NAME="keywords" CONTENT=
"Computer, lights, PC, laser, leds, flashing, leds, kit, multicolor, Case, 12, 12V, volt, volts">
<script type="text/javascript">
<!--
function SwapImage()
{
var doc=document, args=arguments;
doc.$imgSwaps = new Array();
for(var i=2; i<args.length; i+=2)
{
var elem=FindObject(args[i]);
if(elem)
{
doc.$imgSwaps[doc.$imgSwaps.length]=elem;
elem.$src=elem.src;
elem.src=args[i+1];
}
}
}
// -->
</script>
<script type="text/javascript">
<!--
function FindObject(id, doc)
{
var child, elem;
if(!doc)
doc=document;
if(doc.getElementById)
elem=doc.getElementById(id);
else
if(doc.layers)
child=doc.layers;
else
if(doc.all)
elem=doc.all[id];
if(elem)
return elem;
if(doc.id==id || doc.name==id)
return doc;
if(doc.childNodes)
child=doc.childNodes;
if(child)
{
for(var i=0; i<child.length; i++)
{
elem=FindObject(id,child[i]);
if(elem)
return elem;
}
}
var frm=doc.forms;
if(frm)
{
for(var i=0; i<frm.length; i++)
{
var elems=frm[i].elements;
for(var j=0; j<elems.length; j++)
{
elem=FindObject(id,elems[i]);
if(elem) return elem;
}
}
}
return null;
}
// -->
</script>
</head>
<body background="purple-tile.gif" bgcolor="#330066" text="#FFFFFF" alink="#0000FF">
<img src="Lights4yourPC.png" id="Image1" alt="" align="top" border="0" width="704" height="150" style="position:absolute;left:0px;top:0px;width:704px;height:150px;z-index:0">
<div id="bv_" style="position:absolute;left:0px;top:150px;width:118px;height:124px;z-index:1" align="center">
<table border="0" cellpadding="0" cellspacing="0" id="NavigationBar1">
<tr>
<td align="left" valign="top" width="118" height="31"><a href="/"><img id="home" src="home.gif" alt="home" align="top" border="0" width="118" height="31" onmouseover="SwapImage(1,0,'home','home-over.gif')" onmouseout="SwapImage(0,0,'home','home.gif')"></a></td>
</tr>
<tr>
<td align="left" valign="top" width="118" height="31"><a href="pictures.html"><img id="pictures" src="pictures-over.gif" alt="pictures" align="top" border="0" width="118" height="31" onmouseover="SwapImage(1,0,'pictures','pictures-over.gif')" onmouseout="SwapImage(0,0,'pictures','pictures-over.gif')"></a></td>
</tr>
<tr>
<td align="left" valign="top" width="118" height="31"><a href="buy.html"><img id="buy" src="buy.gif" alt="buy" align="top" border="0" width="118" height="31" onmouseover="SwapImage(1,0,'buy','buy-over.gif')" onmouseout="SwapImage(0,0,'buy','buy.gif')"></a></td>
</tr>
<tr>
<td align="left" valign="top" width="118" height="31"><a href="links.html"><img id="links" src="links.gif" alt="links" align="top" border="0" width="118" height="31" onmouseover="SwapImage(1,0,'links','links-over.gif')" onmouseout="SwapImage(0,0,'links','links.gif')"></a></td>
</tr>
</table>
</div>
<img src="line.gif" id="Image2" alt="" align="top" border="0" width="1" height="536" style="position:absolute;left:118px;top:150px;width:1px;height:2296px;z-index:2">
<img src="fade.gif" id="Image3" alt="" align="top" border="0" width="118" height="348" style="position:absolute;left:0px;top:274px;width:118px;height:2172px;z-index:3">
<div id="b_" style="position:absolute;left:124px;top:152px;width:574px;height:32px;z-index:4" align="left">
<font style="font-size:27px" color="#FFFF99" face="Verdana"><b><u>Upload your images!</u></b></font></div>
<div id="v_" style="position:absolute;left:124px;top:202px;width:560px;height:559px;z-index:5" align="left">
<!-- PayPal Logo -->
<a href="#" onclick="javascript:window.open('https://www.paypal.com/us/cgi-bin/webscr?cmd=xpt/cps/popup/OLCWhatIsPayPal-outside','olcwhatispaypal','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=400, height=350');"><img src="space.gif" border="0" width="1" height="1" alt="Acceptance Mark" style="position:absolute;left:600px;top:0px"></a><!-- PayPal Logo -->
<font style="font-size:16px" color="#FFFFFF" face="Verdana">Here you can upload pictures of your PC mods!<br>
<br>
Images will be checked by the administrator before being displayed.<br><br>
Files must be in JPG format for upload.<br><br>
<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">File:<img src="space.gif" width="61" height="1" /></label>
<input type="file" name="file" id="file" /> <br />
<label for="name" >Your Name:</label>
<input type="text" name="name" id="name" /><br />
<label for="comments" >Comments:<img src="space.gif" width="3" height="1" /></label>
<textarea name="comments" id="comments" ></textarea>
<input type="submit" name="submit" value="Submit" />
</form>
<img src="Computer_fan _light.jpg" id="Image4" alt="" align="top" border="0" width="500" height="375" style="position:absolute;left:1px;top:240px;width:500px;height:375px;z-index:7">
<img src="grey.png" id="grey.png" alt="" align="top" border="0" width="600" height="800" style="position:absolute;left:1px;top:615px;width:500px;height:60px;z-index:-9">
<div id="a" style="position:absolute;left:0px;top:625px;width:500px;height:124px;z-index:1" align="center">UPLOADED BY: Joe<br>COMMENTS:</div>
<img src="Glowing_USB.jpg" id="Image5" alt="" align="top" border="0" width="500" height="375" style="position:absolute;left:1px;top:700px;width:500px;height:375px;z-index:8">
<img src="grey.png" id="grey.png" alt="" align="top" border="0" width="600" height="800" style="position:absolute;left:1px;top:1075px;width:500px;height:60px;z-index:-9">
<div id="z" style="position:absolute;left:0px;top:1085px;width:500px;height:124px;z-index:1" align="center">UPLOADED BY: Joe<br>COMMENTS:</div>
<img src="Pimp_My_PC.jpg" id="Image5" alt="" align="top" border="0" width="600" height="800" style="position:absolute;left:1px;top:1160px;width:600px;height:800px;z-index:8">
<img src="grey.png" id="grey.png" alt="" align="top" border="0" width="600" height="800" style="position:absolute;left:1px;top:1960px;width:600px;height:60px;z-index:-9">
<div id="c" style="position:absolute;left:0px;top:1970px;width:600px;height:124px;z-index:1" align="center">UPLOADED BY: Saidmalachi<br>COMMENTS:</div>
<div id="d" style="position:absolute;left:0px;top:2100px;width:600px;height:124px;z-index:1" align="center">
<!-- x10 Exchange code begin -->
<!-- DO NOT ALTER THIS CODE! -->
<script type="text/javascript">
<!--
document.write('<s'+'cript type="text/javascript" src="http://www.x10exchange.com/work.php?n=118&size=1&j=1&c=&code='+new Date().getTime()+'"></s'+'cript>');
//-->
</script>
<noscript>
<iframe src="http://www.x10exchange.com/work.php?n=118&size=1&c=" width="468" height="60" marginwidth="0" marginheight="0" frameborder="0" scrolling="no"></iframe>
</noscript>
<!-- x10 Exchange code -->
</font>
</div>
</div>
</body>
</html>
Last edited: