Jump to content

[SOLVED] changing image filename on upload


hbalagh

Recommended Posts

I have the following code from a script and i need it to change the file name of the images so it wont over right other images that are the same name maybe in a time format can someone please help me with the proper code

 

<?php
include("../includes/db.conf.php");
include("../includes/connect.inc.php");
include ("../includes/functions.inc.php");

echo "<html><body bgcolor='#cccccc'><font face='verdana'><center>";

if (isset($_POST['submit'])){

if (file_exists($_FILES['image']['tmp_name'])){

$photoname=$_FILES['image']['name'];
move_uploaded_file ($_FILES['image']['tmp_name'],"../images/".$photoname);


thumbnail("../images/","../images/thumbs/",$photoname,100);

//$rowa=mysql_fetch_array($mysqlresulta);
}else{

$photoname="nophoto.jpg";
}

$queryn="INSERT into products set name='$_POST[pname]', photo='$photoname', description='$_POST[description]', category='$_POST[category]'";
$mysqlresultn = mysql_query($queryn);

echo "New Product Added<br>";
echo mysql_error();
}
echo "<h3>Add New Product</h3>";
echo "<form action='addproduct.php' method='post' enctype='multipart/form-data'> ";
echo "<table>";
echo "<tr><td>Product Name</td>";
echo "<td><input name='pname' type='text'  size='25' /></td></tr>";
echo "<tr><td colspan=2>Description</td></tr>";
echo "<tr><td colspan=2><textarea name='description' cols='30' rows='5'></textarea></td></tr>";
echo "<tr><td>Photo</td>";
echo "<td><input type='file' name='image'></td></tr>";
echo "<tr><td>Category</td>";
echo "<td><select name='category'>";

$query = "SELECT * from categories ";
$mysqlresult = mysql_query($query);
while($row = mysql_fetch_array($mysqlresult)){
echo "<option value='$row[id]'>$row[name]</option>";
}
echo "<select></td></tr>";

echo "<tr><td colspan=2><input type='submit' name='submit' value='Submit'></td></tr>";
echo "</table>";

echo "</body></html>";
?>

Link to comment
https://forums.phpfreaks.com/topic/82959-solved-changing-image-filename-on-upload/
Share on other sites

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.