Jump to content

Multiple images help


haris244808

Recommended Posts

Hi there. How should i modify this code to make upload multiple files on DB.

AS u can see its for single image but how should i make it for multiple images

 

<?php 

error_reporting(E_ALL);
ini_set('display_errors', '1');

// Start a session for error reporting
session_start();

//Connect to database
require("includes/connect_to_mysql.php");

//check if the button is pressed
if(isset($_POST['submit'])){
// Check to see if the type of file uploaded is a valid image type
function is_valid_type($file)
{
	// This is an array that holds all the valid image MIME types
	$valid_types = array("image/jpg", "image/jpeg", "image/bmp", "image/gif", "image/png");


	if (in_array($file['type'], $valid_types))
		return 1;
	    return 0;
}
// This variable is the path to the image folder where all the images are going to be stored
// Note that there is a trailing forward slash
$TARGET_PATH = "upload_form_images/";

// Get our POSTed variables
$name = $_POST['name'];
$surname = $_POST['surname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$city = $_POST['city'];
$details = $_POST['details'];
$price = $_POST['price'];
$image = $_FILES['image'];

// Sanitize our inputs
$name = mysql_real_escape_string($name);
$surname = mysql_real_escape_string($surname);
$email = mysql_real_escape_string($email);
$phone = mysql_real_escape_string($phone);
$city = mysql_real_escape_string($city);
$details = mysql_real_escape_string($details);
$price = mysql_real_escape_string($price);
$image['name'] = mysql_real_escape_string($image['name']);

// Build our target path full string.  This is where the file will be moved do
// i.e.  images/picture.jpg
$TARGET_PATH .= $image['name'];

// Make sure all the fields from the form have inputs
if ( $name == "" || $surname == "" || $email == "" || $phone == "" || $city == ""  || $details == "" || $price == ""|| $image['name'] == "" )
{
	echo "Te gjithe fushat duhet plotesuar";
	// header("location:upload_form.php");
	exit;
}

// Check to make sure that our file is actually an image
// You check the file type instead of the extension because the extension can easily be faked
if (!is_valid_type($image))
	{
	echo "Fotografite duhet te jene te formateve jpg, jpeg, bmp, gif, ose png";
	//header("Location: upload_form.php");
	exit;
}

// Here we check to see if a file with that name already exists
// You could get past filename problems by appending a timestamp to the filename and then continuing
if (file_exists($TARGET_PATH))
{
	echo "Ju lutem nderroni emrin e fotos.";
	// header("Location: upload_form.php");
	exit;
}

	/*
	// See if that product name is an identical match to another product in the system
	$sql = mysql_query("SELECT id FROM upload_form WHERE name='$name' LIMIT 1");
	$productMatch = mysql_num_rows($sql); // count the output amount
    if ($productMatch > 0) {
		$_SESSION['error'] = 'Ju lutem nderroni emrin sepse egziston ne databaze';
		header("Location: upload_form.php");
		exit();
	}
	*/

	// Lets attempt to move the file from its temporary directory to its new home
if (move_uploaded_file($image['tmp_name'], $TARGET_PATH))
{
	// NOTE: This is where a lot of people make mistakes.
	// We are *not* putting the image into the database; we are putting a reference to the file's location on the server
	$sql = "insert into upload_form (name, surname, email, phone, city, details, price, filename) values ('$name', '$surname', '$email', '$phone', 	  '$city', '$details', '$price', '" . $image['name'] . "')";
	$result = mysql_query($sql) or die ("Futja e te dhenave ne databaze DESHTOI: " . mysql_error());
	echo "Shtimi i te dhenave u krye me SUKSES";
	exit;
}
else
{
	// A common cause of file moving failures is because of bad permissions on the directory attempting to be written to
	// Make sure you chmod the directory to be writeable
	$_SESSION['error'] = "Shtimi i te dhenave NUK u krye me Sukses.  Ju lutem provoni perseri" . mysql_error();
	header("Location: upload_form.php");
	exit;
}
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Qiraja.com</title>
<link rel="stylesheet" href="css/style.css" type="text/css" media="all" />
<!--[if lte IE 6]><link rel="stylesheet" href="css/ie6.css" type="text/css" media="all" /><![endif]-->
<!--[if IE]><style type="text/css" media="screen"> #navigation ul li a em { top:32px; } </style><![endif]-->


</head>
<body>

<!-- Header -->
<div id="header">
<div class="shell">

	<!-- Logo -->
	<h1 id="logo"><a href="#">Company Name</a></h1>
	<!-- End Logo -->

	<!-- Navigation -->
	<div id="navigation">

		<ul>
		    <li><a href="#">Prishtine<span><em></em></span></a></li>
		    <li><a href="#">Prizren<span><em></em></span></a></li>
			<li><a href="#">Ferizaj<span><em></em></span></a></li> 
		    <li><a href="#">Peje<span><em></em></span></a></li>
			<li><a href="#">Mitrovice<span><em></em></span></a></li>
			<li><a href="#">Gjilan<span><em></em></span></a></li>
		    <li class="last"><a href="#">Gjakove<span><em></em></span></a></li>

		</ul>
	</div>  	
</div>
</div>


<div id="slider">
<div class="shell">

	<!-- Slides -->
	<div class="slides">
		<ul>
			<!-- Slide -->
			<li>
			  <form action="upload_form.php" enctype="multipart/form-data" name="myForm" id="myform" method="post">
			    <table width="90%" border="0" cellspacing="0" cellpadding="6">
			      <tr>
			        <td width="20%" align="center">Name</td>
			        <td width="80%"><label>
			          <input name="name" type="text" id="name" size="25" />
			          </label></td>
			        <td align="center">Fotografite</td>
			        <td><label>
			          <input type="file" name="image" id="image" />
			          </label></td>
		          </tr>
			      <tr>
			        <td align="center">Surname</td>
			        <td><label>
			          <input name="surname" type="text" id="surname" size="25" />
			          </label></td>
		          </tr>
			      <tr>
			        <td align="center">Email</td>
			        <td><label>
			          <input name="email" type="text" id="email" size="25" />
			          </label></td>
		          </tr>
			      <tr>
			        <td align="center">Nr. Kontaktues</td>
			        <td><label>
			          <input name="phone" type="text" id="phone" size="25" />
			          </label></td>
		          </tr>
			      <tr>
			        <td align="center">Qyteti</td>
			        <td><select name="city" id="city">
			          <option value=""></option>
			          <option value="Prishtine">Prishtine</option>
			          <option value="Prizren">Prizren</option>
			          <option value="Ferizaj">Ferizaj</option>
			          <option value="Peje">Peje</option>
			          <option value="Mitrovice">Mitrovice</option>
			          <option value="Gjilan">Gjilan</option>
			          <option value="Gjakove">Gjakove</option>
			          </select></td>
		          </tr>
			      <tr>
			        <td align="center">Detajet</td>
			        <td><label>
			          <textarea name="details" id="details" cols="64" rows="5"></textarea>
			          </label></td>
		          </tr>
			      <tr>
			        <td align="center">Cmimi</td>
			        <td><label>
			          <input name="price" type="text" id="price" size="10" />
			          € </label></td>
		          </tr>
			      <tr>
			        <td> </td>
			        <td align="center"><label>
			          <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
			          <input type="submit" name="submit" id="submit" value="Shto te dhenat" />
			          </label></td>
		          </tr>
		        </table>
		      </form>
		  </li>
			<!-- End Slide -->
		    
		    <!-- Slide -->
		    <li>
		    	<div class="slide-info">
			    	<h2><span>Reklamo</span> Shtepine</h2>
			    	<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam arcu ligula, faucibus eu imperdiet eu, bibendum sit amet augue. Sed turpis sem, interdum sit amet egestas a, mattis non libero. Suspendisse tristique nisi sed justo accumsan vel mattis nulla fermentum. Etiam varius est id mi fermentum aliquam.</p>
			    	<p>Quisque quis vestibulum turpis. Sed venenatis ipsum laoreet elit pulvinar vitae pharetra massa dignissim. Curabitur ligula sapien, auctor ut porttitor a, ultricies lobortis dui. Suspendisse lacinia tellus a diam rutrum rhoncus. </p>

					<a href="#" class="more">read more</a></p>
		    	</div>
		    	<span class="slide-image image1"></span>
		    </li>
		    <!-- End Slide -->
		    
		    <!-- Slide -->
		    <li>
		    	<div class="slide-info">
			    	<h2><span>Reklamo</span> Apartmanin</h2>
			    	<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam arcu ligula, faucibus eu imperdiet eu, bibendum sit amet augue. Sed turpis sem, interdum sit amet egestas a, mattis non libero. Suspendisse tristique nisi sed justo accumsan vel mattis nulla fermentum. Etiam varius est id mi fermentum aliquam.</p>
			    	<p>Quisque quis vestibulum turpis. Sed venenatis ipsum laoreet elit pulvinar vitae pharetra massa dignissim. Curabitur ligula sapien, auctor ut porttitor a, ultricies lobortis dui. Suspendisse lacinia tellus a diam rutrum rhoncus. </p>

					<a href="#" class="more">read more</a></p>
		    	</div>
		    	<span class="slide-image image1"></span>
		    </li>
			<!-- End Slide -->
		    
	    </ul>
	</div>
	<!-- End Slides -->

</div>
</div>
<!-- End Slider -->

<!-- Slider Nav -->
<div id="slider-navigation">
<div class="shell">
	<ul>
	    <li><a href="index.php" class="active">Kthehu ne fillim<strong>Home</strong><em class="ico1"></em></a></li>
	    <li><a href="upload_form.php">Shto<strong>Upload</strong><em class="ico2"></em></a></li>
	    <li class="last"><a href="contact_form.php">Kontakti<strong>Contact</strong><em class="ico3"></em></a></li>
	</ul>
</div>
</div>
<!-- End Slider Nav -->

<!-- Main -->
<div id="main">
<div class="shell">

	<!-- Cols -->
	<div class="cols">
		<div class="cl"> </div>

		<!-- Col -->
		<div class="col">
			<h3>Sed Turpis sem</h3>
			<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam arcu ligula, faucibus eu imperdiet eu, bibendum sit amet augue. Sed turpis sem, interdum sit amet egestas a, mattis non libero.<br /><a href="#" class="more">read more</a></p>
			<p>Suspendisse tristique nisi sed justo accumsan vel mattis nulla fermentum. Etiam varius est id mi fermentum aliquam. <br /><a href="#" class="more">read more</a></p>
		</div>
		<!-- End Col -->

		<!-- Col -->
		<div class="col">
			<h3>Ligula amet augue</h3>
			<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam arcu ligula, faucibus eu imperdiet eu, bibendum sit amet augue. <br /><a href="#" class="more">read more</a></p>
			<p>Sed turpis sem, interdum sit amet egestas a, mattis non libero. Suspendisse tristique nisi sed justo accumsan vel mattis nulla fermentum. Etiam varius est id mi fermentum aliquam. <br /><a href="#" class="more">read more</a></p>
		</div>
		<!-- End Col -->

		<!-- Col -->
		<div class="col col-last">
			<h3>Ligula amet augue</h3>
			<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam arcu ligula, faucibus eu imperdiet eu, bibendum sit amet augue. <br /><a href="#" class="more">read more</a></p>
			<p>Sed turpis sem, interdum sit amet egestas a, mattis non libero. Suspendisse tristique nisi sed justo accumsan vel mattis nulla fermentum. Etiam varius est id mi fermentum aliquam. <br /><a href="#" class="more">read more</a></p>
		</div>
		<!-- End Col -->

		<div class="cl"> </div>
	</div>
	<!-- End Cols -->

</div>
</div>


</body>
</html>

Link to comment
Share on other sites

again? This is the third post today containing the same code...

 

Do you understand what your code does? Are you able to find the part that deals with the uploaded files?

 

then all you need to do is change it to run x times (the amount of file that you upload), passing it a different filename every time.

Link to comment
Share on other sites

again? This is the third post today containing the same code...

 

Do you understand what your code does? Are you able to find the part that deals with the uploaded files?

 

then all you need to do is change it to run x times (the amount of file that you upload), passing it a different filename every time.

 

and again you??:P very kind of u.thanx

yes of course i know but i want to create a folder that will put all of them there.

(ex: if someonw ex uploads 3 photo and submits  i want them to send to the same folder, and after that if someone uploads 2 photos send them to different folder than the previous one...to understand who what uploaded)

 

soeey dude.

 

this is the last question for this code

 

and thanx for the reply :)

Link to comment
Share on other sites

well, if you want to know who uploaded what, then you either create folders with their usernames and upload the files into each of those folders, or you just upload them all to the same place , but keep track of the file names and who uploaded in a database.

 

You should add some code to change the file names into something unique, or at the very least, check if the filename already exists before uploading, and add a number to the end if it does. (is_file can check the name for you.)

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.