thanks freind,
presently i am using a simple file uploading code. But it does not rename the files when uploading. (to make them a unique file) And further it does not only upload image files. so there is the isk of users uploading php and stuff.
I searches google a lot. but all ontent give almost the same simple uploading method. no one gives the way to rename the files before uploading, and authorising for only images.
so i have given my coding. can yoou help me to edit it to suit my requierement?
PAGE 1 - FORM
PAGE 2 - File Loading and Writing to Data base
This is the PAGE2 Coding of mine
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
//This is the directory where images will be saved
$target = "images/";
$target = $target . basename( $_FILES['photo']['name']);
//This gets all the other information from the form
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$pic=($_FILES['photo']['name']);
// Connects to your Database
mysql_connect("10.7.486.53", "XXXX", "XXXXXX") or die(mysql_error()) ;
mysql_select_db("XXXX") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone', '$pic')") ;
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>
</body>
</html>
The Following area i tried to include to make a unique ID. But dont know where to enter it
//creates a unique id with the 'about' prefix
$name = uniqid(about);
echo $a;
echo "<br>";
The bellow coding i entered to make only gif file to be uploaded. But it didnt work. I want both gif and jpg to be uploaded
//This is our limit file type condition
if (!($uploaded_type=="image/gif")) {
echo "You may only upload GIF files.<br>";
$ok=0;
}
Please help me to arrange this codings or please help me to clear my problems
please
thanks
sisira