CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Post a PHP snippet (http://www.codingforums.com/forumdisplay.php?f=41)
-   -   Multiple uploads with a single selection. (http://www.codingforums.com/showthread.php?t=266506)

DrDOS 06-28-2012 04:54 AM

Multiple uploads with a single selection.
 
Multiple uploads with a single selection. I modified a single upload script to allow for as many as twenty uploads in one batch, with one selection. Not all browsers support this so have a backup upload. Twenty uploads is the php default and the combined size can't exceed the maximum file size.
PHP Code:

<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type">
<script type="text/javascript">
//Alerts to errors.
window.onerror=function(msg, url, linenumber){var logerror='Error message: ' + msg + '. Url: ' + url + 'Line Number: ' + linenumber;alert(logerror);return false}
</script>
<body >
<?php
//include("./colors.php");
if(isset($_POST['MAX_FILE_SIZE'])){
$newdir $_POST['newdir'];
$dir './Uploads/';
$upload $dir.$newdir;
if (!
file_exists($upload)) {mkdir ($upload); chmod($upload0777); }
$uploaddir $upload."/";
$isAllowed = array("image/jpeg","image/png","image/gif","image/bmp","application/octet-stream");
for ( 
$f $f count($_FILES['userfile']['tmp_name']) ; $f++ )
{    
$ext =  basename($_FILES['userfile']['type'][$f]);
    if  (
move_uploaded_file($_FILES['userfile']['tmp_name'][$f], $uploaddir.$_FILES['userfile']['name'][$f])) {
    if  (
in_array $_FILES['userfile']['type'][$f] , $isAllowed )) echo "File ".$_FILES['userfile']['name'][$f]." is valid, and was successfully uploaded.\n<br>";}
    if  (!
in_array $_FILES['userfile']['type'][$f] , $isAllowed )){echo "File ".$_FILES['userfile']['name'][$f]." was not an allowed type.\n<br>Allowed types are jpeg, png, gif and bmp\n<br>";}
    
$img[$f] = $uploaddir.$_FILES['userfile']['name'][$f];
    print 
"<img src=\"".$img[$f]."\"><br>";
}}
echo 
'<pre>';
print_r($_FILES);
echo 
"<br>";
print 
"</pre>";
?>
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data"  action="index.php" method="POST">
    Make a new folder: <input type="text" name="newdir" />
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name='userfile[]' type='file'  multiple=20 />
<input type="submit" value="Send File" />
</form> 
<br>
<a href="./download.php">Download</a>
<br><br>
</body>
</html>

//  And the download.php used for testing downloads.

<?php
$add 
time();
header('Content-type: image/jpeg');
header('Content-Disposition: attachment; filename="output-'.$add.'.jpg"');
readfile('./Uploads/Drew/drew von kern new 8.JPG');
?>


abduraooft 06-28-2012 07:32 AM

Quote:

include("./colors.php");
Where's that?

DrDOS 06-28-2012 03:05 PM

Quote:

Originally Posted by abduraooft (Post 1245850)
Where's that?

So omit that line, and any other superfluous code. Like I don't have to modify the code of people who upload other example files! Jeesh! BTW colors.php writes a select box with all the 'named' colors with their # values. I could upload that too if you want it.


All times are GMT +1. The time now is 12:42 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.