Jump to content

mutliple file upload and insert into DB -help


dflow

Recommended Posts

im doing smting basically wrong

 

<form action="" method="post">
<?php  
$x=1;
$images = $_GET['images'];
for( $i=0; $i<$images; $i++ )
{
  	echo '<input name="ID" type="hidden" value="1234" />
<br>
<input name="ImageURL['.$i.']" type="file"  value=""/><br><br>';
}

?>

<input name="submit" type="submit" />




<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_query("SET NAMES 'utf8'");
mysql_select_db("international", $con);

if (isset($_POST['submit']))
		for( $i=0; $i<$images; $i++ )
			{
$query=mysql_query("INSERT INTO images (ID,ImageURL) VALUES ('$_POST[iD]','$_POST[imageURL]')");

exit;



mysql_close($con);
} 

			 ?></form>

Link to comment
Share on other sites

a bit more code

<form action="" method="post">
<?php  
$x=1;
$images = $_GET['images'];
for( $i=0; $i<$images; $i++ )
{
  	echo '<input name="ID" type="hidden" value="1234" />
<br>
<input name="ImageURL['.$i.']" type="file" value=""	/><br><br>';
}

?>

<input name="submit" type="submit" />




<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_query("SET NAMES 'utf8'");
mysql_select_db("international", $con);

if (isset($_POST['submit']))
		for( $i=0; $i<$images; $i++ )
			{
				// Where the file is going to be placed 
$target_path = "uploads/";

/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['ImageURL['.$i.']']['name']); 

$query=mysql_query("INSERT INTO images (ID,ImageURL) VALUES ('$_POST[iD]','$_FILES')");

exit;



mysql_close($con);
} 
var_dump($_POST);

			 ?>
</form>

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.