Jump to content

Saving multiples images problem


carlitoway

Recommended Posts

Hi guys Im trying to save multiples images with php, and I did it, but when I save the link on the Database, if I upload 3 images, its show 2 empty links with the raname name I had created, i would like when users upload 3 images its generate Just the 3 url of the images he/she upload, also I would like to save the first image on a diferent var ($foto), im will appreciate any hepl from you! thank you so much
 
this is my code HTML:
 
<form enctype="multipart/form-data" action="recursos/form_process.php" method="POST">
<div id="text">
<div>
<input name="data[]" id="file" type="file" multiple="multiple" />
</div>
</div>
	  
<input type="button" id="add-file-field" name="add" value="Agregar otra foto" />
			  
<input type='hidden' name="action" value="uploadfiles" />
<input type="submit" class="formsubmit" value="Subir y terminar" />
</form>

PHP

<?php 
session_start();

include('conexion.php');
if(isset($_POST['action'])=='uploadfiles')
{
    
//Rename variables
$time = time();

$random = substr(number_format(time() * rand(),0,'',''),0,10);

$seed = str_split('AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789' ); 
shuffle($seed);
$rand = '' ;
	
foreach (array_rand($seed, 10) as $k) $rand .= $seed[$k];	 

//NEW NAME CODE
$new_name = "$rand" . "$random" . "$time";
	
$upload_directory	=	'../uploads/';  
$count_data		=	count($_FILES['data']) ; 
$upload 		= 	$_FILES['data']['name'][$x].',';  
	
    for($x=0;$x<$count_data;$x++) {
        $upload .= $new_name . $_FILES['data']['name']["$x" . ""].','; ##### column Name you can use comma in ending use to stored like this for ex: first.jpg,second.jpg,third.png like this it will stored into database #######
move_uploaded_file($_FILES['data']['tmp_name'][$x], $upload_directory . $new_name . $_FILES['data']['name'][$x]);
	}
$con	= "INSERT INTO provicional (fotos) values ('$upload')";
$query	= mysql_query($con);
}
?>

 
 
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.