How to Upload Images from a Directory & MySQL table


Upload Images from a Directory & PHP & MySQL table:-

//This will automatically refresh the page so timeout wont be an issue.

function set_update_images()
{
$next = get_param(‘next’);
$next = ($next) ? $next:0;

$dir_images = “images folder path”;

$sql_query = “SELECT *
FROM table_name
ORDER BY id
LIMIT $next , 10
” ;
$next+=2;
$uqid = db_query($sql_query);
if(db_num_rows($uqid) > 0)
{
while($arr = db_fetch_array($uqid))
{
$file_info = $dir_images.$arr[‘pcode’].’.jpg’;
if(is_file($file_info))
{
echo ‘<hr>’;
echo $file_info .'<br>’;
$id = $arr[‘id’];
echo ‘<br>’.$arr[‘pcode’];
$_FILES[‘image’][‘name’] = $arr[‘pcode’].’.jpg’;
$_FILES[‘image’][‘tmp_name’] = $file_info;
$_FILES[‘image’][‘type’] = ‘image/jpeg’;
$_FILES[‘image’][‘error’] = 0;

echo ‘<hr>’;
echo $name = $_FILES[“image”][“name”];
$name1 = explode(“.”,$name);
echo ‘<pre>’;
print_r($name1);
echo ‘</pre>’;

$file_name = remove_illegals($name1[0]);
echo ‘<hr>’;
echo $fname = $file_name .”_”.$id.”.”.$name1[1];
echo ‘<hr>’;

//Thumbnail image
$resizeImg->resize($_FILES,’image’,$CFG->thumb_w,$CFG->thumb_h);
if($resizeImg->saveTo($fname, $CFG->dirproducts.”thumb/”))
{
$flag_for_upload_t=1;
}

$updt_qry = “UPDATE table_name SET image= ‘”.$fname.”‘ WHERE id ='”.$id.”‘”;

$uqid1 = db_query($updt_qry);

}
}

?>
<script language=”javascript” type=”text/javascript”>
//alert(“Next batch of <?php //echo $next; ?> starting now!”);
window.location= “products/products.php?next=<?php echo $next; ?>”;
</script>
<?php
}
}