Jump to content

Php Multiply Images Uploading...


TaneskiIle

Recommended Posts

Hello there. I have a problem with inserting a name of the pictures in my table. My table have just 3 fields: id, photo & name.

 

This is html code:

 

 

<form action="nextpage.php" method="post" enctype="multipart/form-data">

<table>
<tr>
<td valign="top">Upload Image: </td>

<td>
<input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="photo" type="file" size="30"><br />
<input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="photo1" type="file" size="30"><br />
<input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="photo2" type="file" size="30"><br />
<input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="photo3" type="file" size="30"><br />
<input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="photo4" type="file" size="30"><br />
<input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="photo5" type="file" size="30"></td>
</tr>
<tr>
<td>
<input type="submit" value="Add" value="Wide button"></td>
</tr>
</table>
</form>

 

This is all php code:

 

<?php
$photo0=($_FILES['photo']['name']);
$photo1=($_FILES['photo1']['name']);
$photo2=($_FILES['photo2']['name']);
$photo3=($_FILES['photo3']['name']);
$photo4=($_FILES['photo4']['name']);
$photo5=($_FILES['photo5']['name']);
//This is the directory where images will be saved
$target = "images/upload/";
$targetx = $target . basename( $_FILES['photo']['name']);
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $targetx))
{
//Tells you if its all ok
}
else {
//Gives and error if its not
}
$targetx = $target . basename( $_FILES['photo1']['name']);
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo1']['tmp_name'], $targetx))
{
//Tells you if its all ok
}
else {
//Gives and error if its not
}
$targetx = $target . basename( $_FILES['photo2']['name']);
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo2']['tmp_name'], $targetx))
{
//Tells you if its all ok
}
else {
//Gives and error if its not
}
$targetx = $target . basename( $_FILES['photo3']['name']);
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo3']['tmp_name'], $targetx))
{
//Tells you if its all ok
}
else {
//Gives and error if its not
}
$targetx = $target . basename( $_FILES['photo4']['name']);
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo4']['tmp_name'], $targetx))
{
//Tells you if its all ok
}
else {
//Gives and error if its not
}
$targetx = $target . basename( $_FILES['photo5']['name']);
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo5']['tmp_name'], $targetx))
{
//Tells you if its all ok
}
else {
//Gives and error if its not
}
include "phpscripts/connect_to_mysql.php";
foreach(array($photo0, $photo1, $photo2, $photo3, $photo4, $photo5) as $value){
$sql="INSERT INTO `images` (`photo`,`name`) VALUES('".$value."', 'spain')";
}
$result=mysql_query($sql);

 

 

I think i have a problem in this fews lines:

 

 

 

foreach(array($photo0, $photo1, $photo2, $photo3, $photo4, $photo5) as $value){
$sql="INSERT INTO `images` (`photo`,`name`) VALUES('".$value."', 'spain')";
}

 

Also if it s possible to stop to do not upload if the user doesn't choose a files.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/268847-php-multiply-images-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.