Multiple files
Multiple files
Can this class be used for multiple files (at once)? What would you recommend is the best way to do this with your class?
Re: Multiple files
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...
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" />??
Re: Multiple files
Yeah, multiple files selected. I would guess something in the class needs to change since the FILES would become multidimensional right?
Re: Multiple files
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.madmax wrote:Yeah, multiple files selected. I would guess something in the class needs to change since the FILES would become multidimensional right?
It would be quite an awkward modification, you might be better off looking for something else or using some custom code.
Re: Multiple files
Bummer, cause your class is very clean and efficient and works well on resizing files as well.