Jump to content

Get names from foreach and insert them in the db


Kleidi

Recommended Posts

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

/**

* 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

################################# UPLOAD IMAGES

	foreach($_FILES as $k => $v){ 

		$img_type = "";

		### $htmo .= "$k => $v<hr />"; 	### print_r($_FILES);

		if( !$_FILES[$k]['error'] && preg_match("#^image/#i", $_FILES[$k]['type']) && $_FILES[$k]['size'] < 1000000){

			$img_type = ($_FILES[$k]['type'] == "image/jpeg") ? ".jpg" : $img_type ;

			$img_type = ($_FILES[$k]['type'] == "image/gif") ? ".gif" : $img_type ;

			$img_type = ($_FILES[$k]['type'] == "image/png") ? ".png" : $img_type ;

			$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 -

			$img_path = $upload_dir.$img_rname;

			copy( $_FILES[$k]['tmp_name'], $img_path );
			chmod("$img_path",0777); 

			$feedback .= "Image and thumbnail created $img_rname<br />";

		}

	}



############################### HTML FORM

while($i++ < $upload_image_limit){

	$form_img .= '<label>Image '.$i.': </label> <input type="file" name="uplimg'.$i.'"><br />';

}



$htmo .= '

	<p>'.$feedback.'</p>

	<form method="post" enctype="multipart/form-data">

		'.$form_img.' <br />

		<input type="submit" value="Upload Images!" style="margin-left: 50px;" />

	</form>

	';	



echo $htmo;

Can anyone help me on this, please?

 

Thank you in advance!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.