Multiple files

Any problems relating to the premium downloads should go in here
Post Reply
madmax
Posts: 3
Joined: Mon Oct 31, 2011 10:12 pm

Multiple files

Post by madmax »

Can this class be used for multiple files (at once)? What would you recommend is the best way to do this with your class?
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Multiple files

Post by jacek »

Yes it can, but you have to do it yourself.

Basically you need to put the code to upload one file in a loop that goes over all of the files.

Something like this...
<?php include('secure_upload.class.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Secure File Upload Class</title>
	</head>
	<body>
		<?php
		
		if (isset($_FILES['image'], $_FILES['video'], $_FILES['song'])){
			foreach (array('image', 'video', 'song') as $key){
				$upload = new secure_upload($key);
				$upload->save_to('./files/' . $upload->name);
				
				if ($upload->error > 0){
					echo '<div>Error: ', $upload->get_error_constant_name(), '</div>';
				}else{
					echo '<img src="files/', $upload->name ,'" alt="', $upload->name, '" />';
				}
			}
		}else{
			?>
			<form action="" method="post" enctype="multipart/form-data">
				<div>
					<input type="file" name="image" />
					<input type="file" name="video" />
					<input type="file" name="song" />
					<input type="submit" value="Upload" />
				</div>
			</form>
			<?php
		}
		
		?>
	</body>
</html>
Or did you mean as in multiple files selected
<input type="file" name="song" multiple="multiple" />
??
Image
madmax
Posts: 3
Joined: Mon Oct 31, 2011 10:12 pm

Re: Multiple files

Post by madmax »

Yeah, multiple files selected. I would guess something in the class needs to change since the FILES would become multidimensional right?
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Multiple files

Post by jacek »

madmax wrote:Yeah, multiple files selected. I would guess something in the class needs to change since the FILES would become multidimensional right?
Okay, you are pretty much right. You would either need to reformat $_FILES or add a loop to all of the methods in the class.

It would be quite an awkward modification, you might be better off looking for something else or using some custom code.
Image
madmax
Posts: 3
Joined: Mon Oct 31, 2011 10:12 pm

Re: Multiple files

Post by madmax »

Bummer, cause your class is very clean and efficient and works well on resizing files as well.
Post Reply