Jump to content

Multi Upload..


Deanznet

Recommended Posts

Hey Im trying to fix this so my users can upload more than 1 file at a time...

 

Heres the code for the html..

 

	<form ENCTYPE="multipart/form-data" method="post" name="form1" action="upload.php">
			<div align="center">
			  <INPUT NAME="attached" TYPE="file"  size="50">
			  <br>
			File extensions allowed: <b>
			<?=implode("</b>, <b>",explode("|",$att_filetypes))?>
			</b><br>
			File size limit: <b>
			<?=$att_max_size?>
			KB</b>

 

Than  after it is posted it gose to upload.php witch has this code:

 

<?	if( $_POST['submit'] && $_FILES['attached']['name'] ){
	$ok_filetypes = explode("|",$att_filetypes);
	if (!$_FILES['attached']['error'] && $_FILES['attached']['size'] > $att_max_size*1024){
		errform('Sorry, but the attached file is too large. Please reduce the size of it\'s contents.'); // #err
		$step = 1;
	}
	$filename = (!$_FILES['attached']['error'] ? substr( basename($_FILES['attached']['name']), -30 ) : '');
	$x = strtolower( substr($_FILES['attached']['name'], -3));
	if($filename && !in_array($x, $ok_filetypes) ){
		errform('Sorry, the filetype you have tried to upload is not allowed.');
		$step = 1;
	}
	if(!$posterr){
		if(!isset($_GET["ipaddress"]) || ($_GET["ipaddress"] == "")) {
			$ipaddress = $_SERVER['REMOTE_ADDR'];
			$local = 1;
		} else {
			$ipaddress = $_GET["ipaddress"];
			$local = 0;
		}
		$uniq = substr( md5(uniqid (rand())), 0, 10 );
		$ext = strtolower( substr($_FILES['attached']['name'], -3));
		move_uploaded_file($_FILES['attached']['tmp_name'], $att_path."/".$uniq.".".$ext );
		$strQuery  = "INSERT INTO images SET ";
		$strQuery .= "filename='".$uniq.".".$ext."',";
		$strQuery .= "ipaddress='{$ipaddress}',";
		$strQuery .= "date='".time()."',";
		$strQuery .= "pkey='{$uniq}',";
		if($myuid){
			$strQuery .= "user='{$myuid}',";
		}
		$strQuery .= "status='1'";
		$result = mysql_query($strQuery) or die( mysql_error() );
		$aid = mysql_insert_id();
		if($aid){
			$filen = $siteurl."/".str_replace('./', '', $att_path)."/".$uniq.".".$ext;
			$filen = str_replace('http://','%%',$filen);
			$filen = str_replace('//','/',$filen);
			$filen = str_replace('%%','http://',$filen);
			$step = 2;
		}else{
			$step = 1;
		}
	}
}else{
	$step = 1;
}
if($step == 1){ ?>

Please can somebody help!

Link to comment
Share on other sites

on the HTML side, add [] to the end of the for elements name so it gets posted as an array

 

<INPUT NAME="attached[]" TYPE="file"  size="50"> <br>
<INPUT NAME="attached[]" TYPE="file"  size="50"> <br>
<INPUT NAME="attached[]" TYPE="file"  size="50"> <br>

 

then on your php side, loop through the array of uploaded files.

<?php
foreach($attached as $file){

... all your code goes here

}
?>

Link to comment
Share on other sites

K i did the Html part... But the php part gives me an error

 

 

  <?	foreach($attached as $file){
if( $_POST['submit'] && $_FILES['attached']['name'] ){
	$ok_filetypes = explode("|",$att_filetypes);
	if (!$_FILES['attached']['error'] && $_FILES['attached']['size'] > $att_max_size*1024){
		errform('Sorry, but the attached file is too large. Please reduce the size of it\'s contents.'); // #err
		$step = 1;
	}
	$filename = (!$_FILES['attached']['error'] ? substr( basename($_FILES['attached']['name']), -30 ) : '');
	$x = strtolower( substr($_FILES['attached']['name'], -3));
	if($filename && !in_array($x, $ok_filetypes) ){
		errform('Sorry, the filetype you have tried to upload is not allowed.');
		$step = 1;
	}
	if(!$posterr){
		if(!isset($_GET["ipaddress"]) || ($_GET["ipaddress"] == "")) {
			$ipaddress = $_SERVER['REMOTE_ADDR'];
			$local = 1;
		} else {
			$ipaddress = $_GET["ipaddress"];
			$local = 0;
		}
		$uniq = substr( md5(uniqid (rand())), 0, 10 );
		$ext = strtolower( substr($_FILES['attached']['name'], -3));
		move_uploaded_file($_FILES['attached']['tmp_name'], $att_path."/".$uniq.".".$ext );
		$strQuery  = "INSERT INTO images SET ";
		$strQuery .= "filename='".$uniq.".".$ext."',";
		$strQuery .= "ipaddress='{$ipaddress}',";
		$strQuery .= "date='".time()."',";
		$strQuery .= "pkey='{$uniq}',";
		if($myuid){
			$strQuery .= "user='{$myuid}',";
		}
		$strQuery .= "status='1'";
		$result = mysql_query($strQuery) or die( mysql_error() );
		$aid = mysql_insert_id();
		if($aid){
			$filen = $siteurl."/".str_replace('./', '', $att_path)."/".$uniq.".".$ext;
			$filen = str_replace('http://','%%',$filen);
			$filen = str_replace('//','/',$filen);
			$filen = str_replace('%%','http://',$filen);
			$step = 2;
		}else{
			$step = 1;
		}
	}
}else{
	$step = 1;
}
if($step == 1){ ?>

 

That right?

 

Error: Parse error: parse error, unexpected $ in upload.php on line 393

Link to comment
Share on other sites

First of all you need to help us to help you. You need to first specify the error if you are getting one (you did not do that in your first post). Also, if you are getting an error and there is a line number you need to tell us which line that is in the code you are posting.

 

But, to respond to your foreach erro, I would bet the problem is that "$attached" is not an array. Where are you specifying the value of $attached?

 

But, now that I look closer it makes no sense to me. Why do you have a foreach loop for the files with all the form elements processed int hat loop? you should just have a foreach loop to process the images - and only the images.

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.