Here are the codes:
PHP Code:
// move file
if(isset($_POST['submit']))
{
$imgcat = (!empty($_POST['imgcat'])) ? $_POST['imgcat'] : '';
if(!empty($imgcat))
{ //make sure it is from same dir
if($imgcat !== $row['img_category'])
{
// image and thumb paths
$oldfile = $row['img_path'] . "/" . $row['img_file'];
$newfile = $row['cat_path']. "/" .$row['img_file'];
$oldthumb = $row['img_path'] . "/" . $row['img_thumb'];
$newthumb = $row['cat_path'] . "/" .$row['img_thumb'];
$path = PATH_DIR . $row['cat_name'];
// move both image and thumb to dir
$dir = opendir($row['cat_path']);
readdir($dir);
rename($oldfile, $newfile);
closedir($dir);
$sql = "UPDATE " . IMAGES_TABLE . "
SET img_category = '$imgcat', img_path = '$path'
WHERE img_id = '$id'";
mysql_query($sql);
}else{
$display_msg = $lang['error_move_file'];
}
}else{
$display_msg = $lang['error_imgcat'];
}
}
Thanks,
Bookmarks