Hello,
I have a simple image multi uploader that uploads images on the folder correctly but i don't know how to get the image names and insert them in the db. The uploader is part of a complex form for adding an article informations (id, name, permanenturl, section, etc) that works correctly.
Image fields in db has names as follows: img1 img2 img3 img4 im5, a field for each image (since i thought that this is the best way to add the images on the article).
The upload sections looks like this:
PHP Code:
<?php
/**
* Smart Image Uploader by @cafewebmaster.com
* Free for private use
* Please support us with donations or backlink
*/
$upload_image_limit = 5; // How many images you want to upload at once?
$upload_dir = "/var/www/tour/te-ngarkuara/oferta/"; // default script location, use relative or absolute path
$data = (date("jnHi")); // Merr daten dhe oren ne momentin e shtimit te fotografise
$img_rname = $data."-".$_FILES[$k]['name']; // shton daten dhe oren perpara emrit te fotografise per te krijuar emer unik
$img_rname = str_replace(" ","-",$img_rname); // Heq hapesirat dhe i zevendeso me -
$data = (date("jnHi")); // Merr daten dhe oren ne momentin e shtimit te fotografise
$img_rname = $data."-".$_FILES[$k]['name']; // shton daten dhe oren perpara emrit te fotografise per te krijuar emer unik
$img_rname = str_replace(" ","-",$img_rname); // Heq hapesirat dhe i zevendeso me -
$imageNames[] = img_rname; // Nova
$img_path = $upload_dir.$img_rname;
copy( $_FILES[$k]['tmp_name'], $img_path );
chmod("$img_path",0777);
$feedback .= "Image and thumbnail acreated $img_rname<br />";
Something like this would create a new row for each image
PHP Code:
$numoffile = 5; // Fix path of your file to be uploaded, don't forget to CHMOD 777 to this folder $file_dir = "/home/link/images/house/".$id."/"; //generate directory mkdir($file_dir, 0777); if (isset($_POST['upload'])) { if(count($_FILES['myfiles']['name'])>0) { //check if any file uploaded for($i=0; $i < count($_FILES['myfiles']['name']); $i++) {//loop the uploaded file array if (trim($_FILES['myfiles']['name'][$i])!="") { $newfile = $file_dir.$_FILES['myfiles']['name'][$i]; //file name move_uploaded_file($_FILES['myfiles']['tmp_name'][$i], $newfile);//upload the file $j++; $my_array[] = $_FILES['myfiles']['name'][$i]; $pics = array_merge($my_array); }
}
} }
foreach ($pics as $t => $v ) { $sql_pic = "INSERT INTO `images` (`image`, `cat_id`, `list_id`) VALUES ('".$v."', '1', '".$id."') "; $result_pic = @mysql_query($sql_pic); if ($result_pic){ echo '<tr> <td colspan="2" class="form_text3">File:'.$v.' has been added to the database<br />'; } }
to put them all in the same field you could implode pics with
Bookmarks