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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.