Jump to content

Multiple file upload


cdoggg94

Recommended Posts

I want to use the type of upload below and edit it so that i can upload multiple files at once instead of just one at a time, any suggestions ?

 

<?php
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("my_db") or die(mysql_error());

$picture = $_FILES['image']['tmp_name'];
$brand = $_POST['brand'];
$year = $_POST['year'];
$story = $_POST['story'];
$description = $_POST['description'];
$pairings = $_POST['pairings'];
$lcbo = $_POST['lcbo'];
$size = $_POST['size'];
$btl = $_POST['btl'];
$price = $_POST['price'];
$lto = $_POST['lto'];
$catagory = $_POST['catagory'];

if(!isset($picture))
echo "";
	else
	{
	$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));	
	$image_name = addslashes($_FILES['image']['name']);
	$image_size = getimagesize($_FILES['image']['tmp_name']);

$max_width = 250;
$max_height = 377;
list($width, $height) = $image_size;
//echo $width.",".$height;
$ratioh = $max_height/$height;
$ratiow = $max_width/$width;
$ratio = min($ratioh, $ratiow);
// New dimensions
$mywidth = intval($ratio*$width);
$myheight = intval($ratio*$height);

	if($image_size==FALSE)
		echo "No image was seleted";
	else{
			if(!$insert = mysql_query ("INSERT INTO product_tbl VALUES ('','".$image_name."','".$image."','".$myheight."','".$mywidth."','".$lcbo."','".$brand."','".$year."','".$size."','".$btl."','".$price."','".$lto."','".$sweet."','".$acid."','".$oak."','".$body."','".$intensity."','','".$story."','".$description."','".$why."','".$catagory."','".$pairings."')"))
				echo "Problem Uploading Image.";
			else{
				$lastid = mysql_insert_id();
				echo "Product added!<p />".$text."<p /><p /> This is what will appear on your page:<p />
				<table border='0'>
				<tr>
					<td valign='top'><img src=get_2.php?Product=$lastid height='".$myheight."' width='".$mywidth."' ></td>
					<td valign='top'>
					  Brand: ".$brand."
					<p>  Company: ".$catagory."</p>
					<p>  Year: ".$year."</p>
					<p>  Story: ".$story."</p>
					<p>  Description: ".$description."</p>
					<p>  Parings: ".$Pairings."</p>
					<p>  LCBO #: ".$lcbo."</p>
					<p>  Size: ".$size."</p>
					<p>  Btl: ".$btl."</p>
					<p>  Price: ".$price."</p>
					<p>  Lto: ".$lto."</p>
					</td>
					</tr>
					</table>

				";
				}
		}

	}

?>

Link to comment
https://forums.phpfreaks.com/topic/262989-multiple-file-upload/
Share on other sites

I have also been trying it in here:

 


<?php
set_time_limit(0);
require_once("Connections/myConnect.php");
mysql_select_db("my_db");
$preName = $_POST['name'];
$preText = $_POST['text'];
$preLink = $_POST['links'];


foreach ($_FILES["picture"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
        $tmp_name = $_FILES["picture"]["tmp_name"][$key];
        $name = $_FILES["picture"]["name"][$key];
        move_uploaded_file($tmp_name, "data/$name");
    }
}


$filetype = $_FILES['pic']['type'];
if($filetype == "image/jpeg" or $filetype == "image/pjpeg") { 
$target_path = "images/".$target_path.basename( $_FILES['pic']['name']); 
$showname = basename( $_FILES['pic']['name']);


if(move_uploaded_file($_FILES['pic']['tmp_name'], $target_path)) {
$querystring = "INSERT INTO presentation_tbl(event3_id,event3_pic,event3_title,event3_content,event3_alt) VALUES(NULL,'".$showname."','".$title."','".$story."','".$alttext."')";
$doquery = mysql_query($querystring);
echo "";
} else{
    echo "There was an error uploading the file, please try again!";
}
}
?>

 

this is very obviously wrong...

 

The $filetype to $showname lines are how i handled a single file upload, again i dont know how to adampt the multi file part to it

my form looks like this:

<form action="admin_presentation2.php" method="post" enctype="multipart/form-data">
<table border="0">
<tr>
<td align="right">Name: </td>
    <td colspan="2"><input name="name" type="text" /></td>
</tr>
<tr>
<td align="right">Text: </td>
    <td colspan="2"><input name="text" type="text" /></td>
</tr>
<tr>
<td align="right">Links: </td>
    <td colspan="2"><input name="links" type="text" /></td>
</tr>
<tr>
<td align="right">Banner: </td>
    <td colspan="2"><input name="banner" type="file" /></td>
    <td>(800px X 152px)</td>
</tr>
<tr>
<td align="right">Logo1: </td>
    <td colspan="2"><input name="logo1" type="file" /></td>
</tr>
<tr>
<td align="right">Logo2: </td>
    <td colspan="2"><input name="logo2" type="file" /></td>
</tr>
<tr>
<td align="right">Logo3: </td>
    <td colspan="2"><input name="logo3" type="file" /></td>
</tr>

<tr>
<td><input name="id" type="hidden" value="" /></td>
    <td colspan="2"><input name="submit" type="submit" value="Add!" /></td>
</tr>

</table>
</form>

 

if that means anything to anyone

sorry that was the old form...

 

this is the new version:

 

<form action="admin_presentation2.php" method="post" enctype="multipart/form-data">
<table border="0">
<tr>
<td align="right">Name: </td>
    <td colspan="2"><input name="name" type="text" /></td>
</tr>
<tr>
<td align="right">Text: </td>
    <td colspan="2"><input name="text" type="text" /></td>
</tr>
<tr>
<td align="right">Links: </td>
    <td colspan="2"><input name="links" type="text" /></td>
</tr>
<tr>
<td align="right">Banner: </td>
    <td colspan="2"><input name="picture[]" type="file" /></td>
    <td>(800px X 152px)</td>
</tr>
<tr>
<td align="right">Logo1: </td>
    <td colspan="2"><input name="picture[]" type="file" /></td>
</tr>
<tr>
<td align="right">Logo2: </td>
    <td colspan="2"><input name="picture[]" type="file" /></td>
</tr>
<tr>
<td align="right">Logo3: </td>
    <td colspan="2"><input name="picture[]" type="file" /></td>
</tr>

<tr>
<td><input name="id" type="hidden" value="" /></td>
    <td colspan="2"><input name="submit" type="button" value="Add!" /></td>
</tr>

</table>
</form>

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.