Jump to content

multiple image uploading


geko21

Recommended Posts

<?php


if (!isset($_SESSION['user_id'])) {
    echo '<p class="login">Please <a href="login.php">log in</a> to access this page.</p>';
    exit();
  }
  else{ 

//Echo out the username of member

echo('<h3 class="login"> ' . $_SESSION['username'] . '\'s Settings </h3>');

     }
mysqli_close($dbc);

$max_no_img=3; // Maximum number of images value to be set here
echo "<form method=post action=upload_project.php enctype='multipart/form-data'>";
echo "<table border='0' width='400' cellspacing='0' cellpadding='0' align=center>";
for($i=1; $i<=$max_no_img; $i++){
echo "<tr><td>images $i</td><td>
<input type=file name='userfile[]' class='bginput'></td></tr>";
}
echo "<tr><td colspan=2 align=center><input type=submit value='Add image'></td></tr>";

echo "</form> </table>";


function findexts ($filename)
{
$filename = strtolower($filename) ;
$exts = split("[/\\.]", $filename) ;
$n = count($exts)-1;
$exts = $exts[$n];
return $exts;
}



for($i=0; $i < 3; $i++)
{

$ext = findexts ($_FILES['userfile']['name'][$i]) ;
$ran = rand () ;
$ran2 = $ran.".";
$add = "upload/";
$add = $add . $ran2.$ext;
$image[$i] = $ran2.$ext ;
move_uploaded_file($_FILES['userfile']['tmp_name'][$i], $add);
$new_id = $image[$i]++;
$pic =$new_id++;

$query = "INSERT INTO cycles (large_image1,large_image2,large_image3)". "VALUES ('$ran.$ext','$new_id','$pic')";

mysql_query($query) or die('database Query Error!');
}
echo "Successfully uploaded the image";


exit;
?>

 

Hi guys, I've been using this code to try and get image paths to upload to a database and store the image in a file called "upload/" but it doesnt seem to be working. I am also using two tables in my database and need to add into the script the user session id (user_id primary) from the current page and store it into the (user_id foreign) for the cycles tables.

 

thanks

:)

Link to comment
https://forums.phpfreaks.com/topic/233802-multiple-image-uploading/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.