note 78192 added to features.file-upload.multiple
| From: | andrex dot da at gmail dot com | Date: | Tue, 02 Oct 2007 17:21:39 +0000 |
| Subject: | note 78192 added to features.file-upload.multiple | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130988@lists.php.net to get a copy of this message | ||
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/');
?>
----
Server IP: 69.147.83.197
Probable Submitter: 200.12.237.78
----
Manual Page -- http://www.php.net/manual/en/features.file-upload.multiple.php
Edit -- https://master.php.net/note/edit/78192
Del: integrated -- https://master.php.net/note/delete/78192/integrated
Del: useless -- https://master.php.net/note/delete/78192/useless
Del: bad code -- https://master.php.net/note/delete/78192/bad+code
Del: spam -- https://master.php.net/note/delete/78192/spam
Del: non-english -- https://master.php.net/note/delete/78192/non-english
Del: in docs -- https://master.php.net/note/delete/78192/in+docs
Del: other reasons-- https://master.php.net/note/delete/78192
Reject -- https://master.php.net/note/reject/78192
Search -- https://master.php.net/manage/user-notes.php