Multiple files
Posted: Wed Nov 23, 2011 8:05 pm
Can this class be used for multiple files (at once)? What would you recommend is the best way to do this with your class?
<?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" />??
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?