note 78192 deleted from features.file-upload.multiple by felipe
| From: | felipe@php.net | Date: | Mon, 24 Dec 2007 03:06:38 +0000 |
| Subject: | note 78192 deleted from features.file-upload.multiple by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-133965@lists.php.net to get a copy of this message | ||
Note Submitter: andrex dot da at gmail dot com
Reason: 1
----
I've made a function to upload many files at once, you can give an array, or send an alone
file.
Change the array with the extensions you want.
<?php
// Andrés Ortiz
function UploadFiles($files,$folder){
$extperms = array('gif','jpg','png');
if(is_array($files)){
for($i=0;$i<count($files['error']);$i++){
if($files['error'][$i] == 0){
$tmpname = $files['tmp_name'][$i];
$ext = strtolower(substr($files['name'][$i], -3, 3));
$filename = $files['name'][$i];
if(in_array($ext, $extperms)){
$endpath[$i] = $folder . $files['name'][$i];
if(!@move_uploaded_file($files['tmp_name'][$i], $endpath[$i])){
$logger['UploadFiles'][] = 'Couldn\'t upload the file, try again
later';
}
else{
if(!@chmod($endpath[$i], 0777)){
$logger['UploadFiles'][] = 'Couldn\'t change permissions file,
ignoring...';
}
}
$weigth[$i] = ($tam = @stat($endpath[$i]))?$tam[7]:$endpath[$i];
}
else{
$logger['UploadFiles'][] = 'You must upload files with image extensions (JPG,
PNG, GIF)';
}
}
else{
$logger['UploadFiles'][] = 'The files have errors, check first and then try
again';
return false; // If you don't want what the others uploads die, comment this.
}
}
return array('files' => $endpath, 'stat' => $weigth);
}
else{
if($files['error'] == 0){
$tmpname = $files['tmp_name'];
$ext = strtolower(substr($files['name'], -3, 3));
$filename = $files['name'];
if(in_array($ext, $extperms)){
$endpath = $folder . $files['name'];
if(!@move_uploaded_file($files['tmp_name'], $endpath)){
$logger['UploadFiles'][] = 'Couldn\'t upload the file, try again
later';
}
else{
if(!@chmod($endpath, 0777)){
$logger['UploadFiles'][] = 'Couldn\'t change permissions file,
ignoring...';
}
}
$weigth = ($tam = @stat($endpath))?$tam[7]:$endpath[$i];
}
else{
$logger['UploadFiles'][] = 'You must upload files with image extensions (JPG,
PNG, GIF)';
}
}
else{
$logger['UploadFiles'][] = 'The files have errors, check first and then try
again';
return false;
}
return array('files' => $endpath, 'stat' => $weigth);
}
if(count($logger['UploadFiles'])>0){
echo '<pre><br /> <b>Some Errors were found.</b><hr /><br
/>';
print_r($logger);
echo '</pre>';
}
}
/*
function [array],[Destination Folder]
*/
UploadFiles($_FILES,'uploads/files/');
?>