hbalagh Posted December 23, 2007 Share Posted December 23, 2007 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 More sharing options...
papaface Posted December 23, 2007 Share Posted December 23, 2007 $photoname= md5(rand()) . $_FILES['image']['name']; You could use that. Link to comment https://forums.phpfreaks.com/topic/82959-solved-changing-image-filename-on-upload/#findComment-421955 Share on other sites More sharing options...
hbalagh Posted December 23, 2007 Author Share Posted December 23, 2007 $photoname= md5(rand()) . $_FILES['image']['name']; You could use that. great thanks, works like a charm Link to comment https://forums.phpfreaks.com/topic/82959-solved-changing-image-filename-on-upload/#findComment-421960 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.