iceblox Posted May 10, 2008 Share Posted May 10, 2008 Hi Guys, I have an upload script and im trying to rename the file based on the count of images already in the database. I have tried a number of different things and keep failing. Has any got any ideas? This is the code.. if(!empty($_POST["addbutton"])) { $images = array(); while(list($key, $value) = each($_FILES["images"]["name"])) { if(!empty($value)) { $tmp = $_FILES["images"]["tmp_name"][$key]; $new = "img/gallery/images/$value"; if(copy($tmp, $new)) $images[] = $value; } } $sql = "INSERT INTO ".$prefix."_galleryimage (catid, image, thumb, title, active) VALUES ( '".forSql($_POST["catid"])."', '".$images[0]."', '".$images[1]."', '".forSql($_POST["title"])."', '".forSql($_POST["active"])."')"; $result = $db->sql_query($sql); if($result) $status = "<b>".$_POST["title"] . " added successfully</b>"; else { print_r($db->sql_error($result)); $status = "<b>Error could not add news. " . var_dump($db->sql_error($result),true); } } } Link to comment https://forums.phpfreaks.com/topic/105003-uploads-and-renaming-files/ Share on other sites More sharing options...
iceblox Posted May 10, 2008 Author Share Posted May 10, 2008 Anyone got any suggestions? Link to comment https://forums.phpfreaks.com/topic/105003-uploads-and-renaming-files/#findComment-537806 Share on other sites More sharing options...
BlueSkyIS Posted May 10, 2008 Share Posted May 10, 2008 select count() of the images in the database. add 1 for the new image name. write the new image to disk using the new image name. update the table with the new image name. Link to comment https://forums.phpfreaks.com/topic/105003-uploads-and-renaming-files/#findComment-537813 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.