Jump to content

multiple upload script


dennismonsewicz

Recommended Posts

I have the following script that uses Flash to upload multiple files.

 

<form id="form1" action="index.php" method="post" enctype="multipart/form-data">
            
                <table width="500" style="margin-left: 25px;">
                    <tr valign="top">
                        <td>
                            <div id="flashUI1" style="display: none;">
                                <fieldset class="flash" id="fsUploadProgress1">
                                    <legend>Large File Upload Site</legend>
                                </fieldset>
                                <div>
                                    <input type="button" value="Upload file (Max 100 MB)" onclick="upload1.selectFiles()" style="font-size: 8pt;" />
                                    <input id="btnCancel1" type="button" value="Cancel Uploads" onclick="cancelQueue(upload1);" disabled="disabled" style="font-size: 8pt;" /><br />
                                </div>
                            </div>
                            <div id="degradedUI1">
                                <fieldset>
                                    <legend>Large File Upload Site</legend>
                                    <input type="file" name="anyfile1" /> (Any file, Max 100 MB)<br/>
                                </fieldset>
                                <div>
                                    <input type="submit" value="Submit Files" />
                                </div>
                            </div>
                        </td>
                        <!--<td>
                            <div id="flashUI2" style="display: none;">
                                <fieldset class="flash" id="fsUploadProgress2">
                                    <legend>Small File Upload Site</legend>
                                </fieldset>
                                <div>
                                    <input type="button" value="Upload file (Max 200KB)" onclick="upload2.selectFiles()" style="font-size: 8pt;" />
                                    <input id="btnCancel2" type="button" value="Cancel Uploads" onclick="cancelQueue(upload2);" disabled="disabled" style="font-size: 8pt;" /><br />
                                </div>
                            </div>
                            <div id="degradedUI2">
                                <fieldset>
                                    <legend>Small File Upload Site</legend>
                                    <input type="file" name="anyfile2" /> (Any file, Max 200KB)<br/>
                                </fieldset>
                                <div>
                                    <input type="submit" value="Submit Files" />
                                </div>
                            </div>
                        </td>-->
                    </tr>
                </table>
            
        </form>

 

Here is my JS that loads the flash variables:

 

<script type="text/javascript">
	var upload1, upload2;

	window.onload = function() {
		upload1 = new SWFUpload({
			// Backend Settings
			upload_url: "upload.php",	// Relative to the SWF file (or you can use absolute paths)
			post_params: {"PHPSESSID" : "<?php echo session_id(); ?>"},

			// File Upload Settings
			file_size_limit : "102400",	// 100MB
			file_types : "*.*",
			file_types_description : "All Files",
			file_upload_limit : "10",
			file_queue_limit : "0",

			// Event Handler Settings (all my handlers are in the Handler.js file)
			file_dialog_start_handler : fileDialogStart,
			file_queued_handler : fileQueued,
			file_queue_error_handler : fileQueueError,
			file_dialog_complete_handler : fileDialogComplete,
			upload_start_handler : uploadStart,
			upload_progress_handler : uploadProgress,
			upload_error_handler : uploadError,
			upload_success_handler : uploadSuccess,
			upload_complete_handler : uploadComplete,

			// Flash Settings
			flash_url : "includes/swfupload/swfupload_f8.swf",	// Relative to this file (or you can use absolute paths)

			swfupload_element_id : "flashUI1",		// Setting from graceful degradation plugin
			degraded_element_id : "degradedUI1",	// Setting from graceful degradation plugin

			custom_settings : {
				progressTarget : "fsUploadProgress1",
				cancelButtonId : "btnCancel1"
			},

			// Debug Settings
			debug: false
		});

		upload2 = new SWFUpload({
			// Backend Settings
			upload_url: "upload.php",	// Relative to the SWF file (or you can use absolute paths)
			post_params: {"PHPSESSID" : "<?php echo session_id(); ?>"},

			// File Upload Settings
			file_size_limit : "200",	// 200 kb
			file_types : "*.jpg;*.gif;*.png",
			file_types_description : "Image Files",
			file_upload_limit : "10",
			file_queue_limit : "2",

			// Event Handler Settings (all my handlers are in the Handler.js file)
			file_dialog_start_handler : fileDialogStart,
			file_queued_handler : fileQueued,
			file_queue_error_handler : fileQueueError,
			file_dialog_complete_handler : fileDialogComplete,
			upload_start_handler : uploadStart,
			upload_progress_handler : uploadProgress,
			upload_error_handler : uploadError,
			upload_success_handler : uploadSuccess,
			upload_complete_handler : uploadComplete,

			// Flash Settings
			flash_url : "includes/swfupload/swfupload_f8.swf",	// Relative to this file (or you can use absolute paths)

			swfupload_element_id : "flashUI2",		// Setting from graceful degradation plugin
			degraded_element_id : "degradedUI2",	// Setting from graceful degradation plugin

			custom_settings : {
				progressTarget : "fsUploadProgress2",
				cancelButtonId : "btnCancel2"
			},

			// Debug Settings
			debug: false
		});

     }
</script>

 

Now how in the blue world do I send the files to a PHP page to handle what I need it to do?

 

Link to comment
Share on other sites

question. Any particular reason you using JS and flash to do this??

 

Also just a FYI you won't be able to use php to upload 100MB files unless you have access to the php.ini file. Default is 2MB.

 

Ray

 

 

Link to comment
Share on other sites

php will do it also here is a bit of code I used in the past for uploading pictures.

 

<?php
$absolute_path = "path/to/folder/"; //Absolute path to where files are uploaded ending with "/"
$size_limit = "yes"; //do you want a size limit yes or no.
$limit_size = "600000"; //How big do you want size limit to be in bytes
$limit_ext = "yes"; //do you want to limit the extensions of files uploaded
$ext_count = "4"; //total number of extensions in array below
$extensions = array(".jpg", ".jpeg", ".png", ".gif"); //List extensions you want files uploaded to be

if(!isset($_POST['submit'])){
$extens = '';

        if (($extensions == "") or ($extensions == " ") or ($ext_count == "0") or ($ext_count == "") or ($limit_ext != "yes") or ($limit_ext == "")) {
           $extens = "any extension";
        } else {
        $ext_count2 = $ext_count+1;
        for($counter=0; $counter<$ext_count; $counter++) {
            $extens .= "  $extensions[$counter]";
        }
        }
        if (($limit_size == "") or ($size_limit != "yes")) {
            $limit_size = "any size";
        } else {
            $limit_size .= " bytes";
            $mb_size = ($limit_size/1000000);
        }
        $pichead = "<li><font size=\"2\" color=660000>File extension must be $extens<b>";
        $pichead .="</b></font>
        <li><font size=\"2\" color=660000>Maximum file size is $limit_size ($mb_size MB)</font></li>
        <li><font size=\"2\" color=660000>No spaces in the filename</font></li>";
?>
<html>
<head>
<title>HTML Form for uploading image to server</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data">
<html>
<title>Add Vehicle Form</title>
<body>
<p><? echo $pichead; ?></p>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<p>Pictures:<br />
<?php
$files = 6;
for($i=1; $i<=$files; $i++){
echo "File $i <input type=\"file\" name=\"pictures[]\" /><br />\n";
}
?>
<input type="submit" name=submit value="Send" />
</p>
</form>
<?php
} else {
$i=0;
//$photoarray = array();
  foreach ($_FILES["pictures"]["error"] as $key => $error) {
  $file_name =  $_FILES["pictures"]['name'][$i]; // can call this anything you like this will take the original name
  $file =  $_FILES["pictures"]['tmp_name'][$i];
  $file_size = $_FILES["pictures"]['size'][$i];
  //$photoarray[$i+1]= $file_name;
  $endresult = "<font size=\"4\" color=990000>$file_name uploaded successfully</font>";
    if ($file_name == "") {
    $pic = $i+1;
    $endresult = "<font size=\"4\" color=990000>Pic#$pic Not selected</font>";
    }else{
      if(file_exists($absolute_path.$file_name)) {
      $endresult = "<font size=\"4\" color=990000>File Already Existed</font>";
      } else {
        if (($size_limit == "yes") && ($limit_size < $file_size)) {
        $endresult = "<font size=\"4\" color=990000>File was to big</font>";
        } else {
        $ext = strrchr($file_name,'.');
          if (($limit_ext == "yes") && (!in_array($ext,$extensions))) {
          $endresult = "<font size=\"4\" color=990000>File is wrong type</font>";
          }else{
          move_uploaded_file($file, $absolute_path.$file_name);
          }
        }
      }
    }
  $i++;
  echo $endresult."<br>";
  }
}
?>
</body>
</html>

 

Ray

 

 

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.