Multiple image upload

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 348 Views - Last Post: 27 January 2014 - 02:51 AM

#1 VB ASRAAF007  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 87
  • Joined: 11-April 12

Multiple image upload

Posted 26 January 2014 - 10:20 PM

i have a problem in multiple image upload, when i upload, there's only 1 image which go to the targeted directory and database. i need two images to go directory and database...any help please?

this is my form and php code



<form action="test.php" method="post" enctype="multipart/form-data">
Keywords: <input style="margin-left:35px;" type="text" name="keyword" /><br />
Name: <input style="margin-left:60px;" type="text" name="name" /><br />
Name2: <input style="margin-left:60px;" type="text" name="name2" /><br />
Categorie: <input style="margin-left:40px;" type="text" name="categorie" /><br />
Lieu: <input style="margin-left:70px;" type="text" name="lieu" /><br /><br />


<input type="file" name="file[]" multiple="multiple" /><input type="file"     name="file_2[]" multiple="multiple"/><input type="submit" name="submit" value="Upload" />




</form>

<?php



$connect = mysql_connect("localhost", "root", "");
$select_db = mysql_select_db("yakatrouver_test", $connect);

if(@$_POST['submit']){

$keywords = $_POST['keyword'];
$name = $_POST['name'];
$name2 = $_POST['name2'];
$categorie = $_POST['categorie'];
$lieu = $_POST['lieu'];





$file = $_FILES['file'];
$file_name = $file['name'];
$file_type = $file['type'];
$file_size = $file['size'];
$file_path = $file['tmp_name'];

$file_2 = $FILES['file_2'];
$file_name_2 = $file['name'];
$file_type_2 = $file['type'];
$file_size_2 = $file['size'];
$file_path_2 = $file['tmp_name'];



if($file_name!="" &&     ($file_type="image/jpeg"||$file_type="image/png"||$file_type="image/gif") && $file_size<=2000000)
if(move_uploaded_file ($file_path, 'pictures_uploaded/' .$file_name))

$query = mysql_query("INSERT INTO `user_input`(keyword, name,  categorie, lieu) VALUES ('$keywords', '$name', '$categorie', ' $lieu')");    

$query = mysql_query("UPDATE `user_input` set image='pictures_uploaded/$file_name' WHERE `name`='$name'");
    if($query  == true)
    {
        echo "file Uploaded";

    }



}


$result = mysql_query("SELECT * FROM `user_input` WHERE `image`=''") or     die(mysql_error());

while($row = mysql_fetch_array($result))



?>




Is This A Good Question/Topic? 0
  • +

Replies To: Multiple image upload

#2 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3519
  • View blog
  • Posts: 10,159
  • Joined: 08-June 10

Re: Multiple image upload

Posted 26 January 2014 - 11:31 PM

Quote

there's only 1 image which go to the targeted directory and database.

because thatís what the code is coded to do.

besides that, youíre using the outdated and deprecated mysql_* functions (see signature) and youíre totally susceptible to SQL Injection.
Was This Post Helpful? 0
  • +
  • -

#3 VB ASRAAF007  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 87
  • Joined: 11-April 12

Re: Multiple image upload

Posted 26 January 2014 - 11:35 PM

i need to upload at least 2 images ...how will i
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3519
  • View blog
  • Posts: 10,159
  • Joined: 08-June 10

Re: Multiple image upload

Posted 26 January 2014 - 11:36 PM

what do you think you would need to do?
Was This Post Helpful? 0
  • +
  • -

#5 VB ASRAAF007  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 87
  • Joined: 11-April 12

Re: Multiple image upload

Posted 26 January 2014 - 11:39 PM

i need to upload two images to the directory and path to database.. only 1 is uploading...can u help?
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3519
  • View blog
  • Posts: 10,159
  • Joined: 08-June 10

Re: Multiple image upload

Posted 26 January 2014 - 11:42 PM

what do you usually do if your code does something once, but you want it done twice?
Was This Post Helpful? 0
  • +
  • -

#7 VB ASRAAF007  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 87
  • Joined: 11-April 12

Re: Multiple image upload

Posted 26 January 2014 - 11:43 PM

copy and paste the code to do the second 1?
Was This Post Helpful? 0
  • +
  • -

#8 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3519
  • View blog
  • Posts: 10,159
  • Joined: 08-June 10

Re: Multiple image upload

Posted 26 January 2014 - 11:44 PM

thatís a pretty good idea to start with.
Was This Post Helpful? 0
  • +
  • -

#9 VB ASRAAF007  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 87
  • Joined: 11-April 12

Re: Multiple image upload

Posted 26 January 2014 - 11:54 PM

i still cant figure it out and now the first image also is not uploading and the data also is not entering the datbase.. im dead
Was This Post Helpful? 0
  • +
  • -

#10 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3519
  • View blog
  • Posts: 10,159
  • Joined: 08-June 10

Re: Multiple image upload

Posted 26 January 2014 - 11:56 PM

as long as you can post, youíre not dead.

besides that, only if you show us what youíve got we can make a comment on it.
Was This Post Helpful? 0
  • +
  • -

#11 VB ASRAAF007  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 87
  • Joined: 11-April 12

Re: Multiple image upload

Posted 27 January 2014 - 12:01 AM

my html and php codes

<form action="test.php" method="post" enctype="multipart/form-data">
Keywords: <input style="margin-left:35px;" type="text" name="keyword" /><br />
Name: <input style="margin-left:60px;" type="text" name="name" /><br />
Name2: <input style="margin-left:60px;" type="text" name="name2" /><br />
Categorie: <input style="margin-left:40px;" type="text" name="categorie" /><br />
Lieu: <input style="margin-left:70px;" type="text" name="lieu" /><br /><br />


<input type="file" name="file[]" />
<input type="file" name="file[]" />
<input type="submit" name="submit" value="Upload" />


</form>





<?php
	


	
$connect = mysql_connect("localhost", "root", "");
$select_db = mysql_select_db("yakatrouver_test", $connect);

	if(@$_POST['submit']){
		
	$keywords = $_POST['keyword'];
	$name = $_POST['name'];
	$categorie = $_POST['categorie'];
	$lieu = $_POST['lieu'];
			

	$file = $_FILES['file'];
	$file_name = $file['name'];
	$file_type = $file['type'];
	$file_size = $file['size'];
	$file_path = $file['tmp_name'];
	
	
	if($file_name!="" && ($file_type="image/jpeg"||$file_type="image/png"||$file_type="image/gif") && $file_size<=2000000)
	if(move_uploaded_file ($file_path, 'pictures_uploaded/' .$file_name))
	
		$query = mysql_query("INSERT INTO `user_input`(keyword, name, categorie, lieu) VALUES ('$keywords', '$name', '$categorie', ' $lieu')");	
		
		$query = mysql_query("UPDATE `user_input` set image='pictures_uploaded/$file_name' WHERE `name`='$name'");
		if($query == true)
		{
			echo "file Uploaded";
			
		}
}

	
	$result = mysql_query("SELECT * FROM `user_input` WHERE `image`=''") or die(mysql_error());
	while($row = mysql_fetch_array($result))

?>






and it returns me that error


Notice: Array to string conversion in C:\xampp\htdocs\yakatrouver_test\test.php on line 53



with these codes, i no many things are missing, but i really need to upload at least 2 images to the folder and path to database...

This post has been edited by VB ASRAAF007: 27 January 2014 - 12:03 AM

Was This Post Helpful? 0
  • +
  • -

#12 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3519
  • View blog
  • Posts: 10,159
  • Joined: 08-June 10

Re: Multiple image upload

Posted 27 January 2014 - 12:27 AM

which is line #53?
Was This Post Helpful? 0
  • +
  • -

#13 VB ASRAAF007  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 87
  • Joined: 11-April 12

Re: Multiple image upload

Posted 27 January 2014 - 02:33 AM

its ok, i figured it out..it works well now...thanks a lot...

p.s the line 53 was
$query = mysql_query("UPDATE user_input set image='pictures_uploaded/$file_name' WHERE name='$name'");

Was This Post Helpful? 0
  • +
  • -

#14 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3519
  • View blog
  • Posts: 10,159
  • Joined: 08-June 10

Re: Multiple image upload

Posted 27 January 2014 - 02:49 AM

now remains the issue with the SQl Injection.
Was This Post Helpful? 0
  • +
  • -

#15 VB ASRAAF007  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 87
  • Joined: 11-April 12

Re: Multiple image upload

Posted 27 January 2014 - 02:50 AM

exact...how can i prevent this ? addstriplashes?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2