Deanznet Posted September 12, 2007 Share Posted September 12, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/69116-multi-upload/ Share on other sites More sharing options...
micah1701 Posted September 13, 2007 Share Posted September 13, 2007 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/69116-multi-upload/#findComment-347459 Share on other sites More sharing options...
Deanznet Posted September 13, 2007 Author Share Posted September 13, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/69116-multi-upload/#findComment-347471 Share on other sites More sharing options...
Deanznet Posted September 13, 2007 Author Share Posted September 13, 2007 Kinda fixed it now i get Warning: Invalid argument supplied for foreach() in /home/content/c/h/a/changeme/html/crapp.php on line 250 Witch is the foreach code... Quote Link to comment https://forums.phpfreaks.com/topic/69116-multi-upload/#findComment-347509 Share on other sites More sharing options...
Deanznet Posted September 13, 2007 Author Share Posted September 13, 2007 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/69116-multi-upload/#findComment-347855 Share on other sites More sharing options...
Psycho Posted September 13, 2007 Share Posted September 13, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/69116-multi-upload/#findComment-347858 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.