Jump to content

Upload Class - need help


Preslav

Recommended Posts

 

Hello,

I apologize if I'm in the wrong selection.Nov in sayta.Razbrah site of php.net.My English is very bad, and please excuse me if you make mistakes and I can properly express.

 

I want to do multi upload class, which could almost anything related to uploading files.But doing to one place and have problem.when try to crawl array of names of files and try to check whether there are such names can not is make it.I hope is that at least you will help me because the Bulgarian forums, did not wish anyone to help me.

 

<?php

include("upload.class.php");
$ext     = array(
           'mp3','avi','jpg','gif','bmp'
);
$type    = array(
            'image/jpeg'
);

$setings = array (
            'folder' => '. / ups /', # the folder in which files will be uploaded
            'folder_exist' => 'TRUE', # whether to check for existing folder
            'folder_permission' =>'0775 ', # right folder
            'upload_ext' => $ext, # which files to upload (extension)
            'upload_type' => $type, # which files to upload (type)
            'upload_t' =>'', # in which key $ _FILES to be picked up (NULL = ALL KEY)
            'file' => $_FILES, # problenliva upload / no change /
            'file_size' =>'83886080 ', # 80 mb = 83886080 byte
            'ceche' => 'TRUE', # whether to caches uploaded
            'ceche_folder' => '. / ups / tmp /', # in which folder to be cached
            'rename' => 'TRUE', # whether to renamed files uploaded
            'rename_code' => 'md5', # if the file renamed to function md5 (), sha1 ()....
            'rename_exist' => 'md5' # if the file renamed to function md5 (), sha1 ()....
  );


$upload = new uploads($setings);

$upload->uploads();

echo "<form enctype='multipart/form-data' action='?act=1' method='POST'>";
echo "File:<br/>
<input name='uploaded[]' type='file'/>
<input name='uploaded[]' type='file'/>
<input name='uploaded[]' type='file'/>
<input name='uploaded[]' type='file'/>
<br/>
<input name='uploaded2[]' type='file'/>
<input name='uploaded2[]' type='file'/>
<br />
<input type='submit' value='Upload'/>";
echo "</form>";

<?php
/* Autor: Preslav Panayotov |#| e-mail: [email protected] ;
* Editors & Developers:
*        YOUR_NAME & YOUR_E-MAIL
* Version: b0.0.1 (alfa = a , beta = b );
*
* funciite in  class:
* 
* pasive_chec  => pasive function for  checking  exist folder;
*
* chec_file    => check and iset data in varibians ;
*
* shushestvuva => check before uploading a file that exists.
*               if exists whether it should be renamed or to replace
*
*
* 
*/
class uploads{
private $folder;
private $folder_exist;
private $folder_permission;
private $upload_ext;
private $upload_type;
private $file;
private $ceche;
private $ceche_folder;
private $file_key = array();  /* chec_file() */
private $file_upload = array();/* chec_file() */
private $file_key_nums;
private $file_upload_nums;

public function __construct($setings){
    $this->folder               = $setings['folder'];
    $this->folder_exist         = $setings['folder_exist'];
    $this->folder_permission    = $setings['folder_permission'];
    $this->upload_ext           = $setings['upload_ext'];
    $this->upload_type          = $setings['upload_type'];
    $this->file                 = $setings['file'];
    $this->file_size            = $setings['file_size'];
    $this->upload_t             = $setings['upload_t'];
    $this->upload_type          = $setings['upload_type'];
    $this->upload_ext           = $setings['upload_ext'];
    $this->ceche                = $setings['ceche'];
    $this->ceche_folder         = $setings['ceche_folder'];
    $this->rename               = $setings['rename'];
    $this->rename_exist         = $setings['rename_exist'];
    $this->rename_code          = $setings['rename_code'];

   
}

function pasive_chec()
    {
        if($this->folder_exist == TRUE){
            if(!is_dir($this->folder)) { mkdir($this->folder,$this->folder_permission);}
        }
        if($this->folder_permission != NULL){
            $folder = fileperms($this->folder);
            if($this->folder_permission != $folder){
                chmod($this->folder , $this->folder_permission);
            }
        }
        if($this->ceche == TRUE){
            if(!is_dir($this->ceche_folder)){ mkdir($this->ceche_folder,$this->folder_permission);}
        }
    
    }

function chec_file(){
    if($this->file != NULL){
        $i = 0;
        $this->file_key_nums = 0;
        $this->file_upload_nums = 0;
        foreach($this->file as $key=>$value){
            $this->file_key[$i] = $key;
            $this->file_upload[$i] = $value;
            $i++; $this->file_key_nums++; $this->file_upload_nums++;
        }
    }
}

function sushtestvuva(){
   foreach($this->file as $key=>$value){
       $i=0;
       foreach($value['name'] as $key1=>$value1){
             if(file_exists($this->folder.$value1) == TRUE){
               $this->file[$key]['name'][$i] = $this->renams($value1);
             }
             $i++;
      }
    }
}

function renams($file_name){
    $name = basename($file_name);
    $razshirenie = substr($name, strrpos($name, '.'));
    $nname = array_map($this->rename_exist,$name);
    $nname.= ".".$razshirenie;
    return $new_name;
}

function uploads(){
    $this->pasive_chec();
    $this->sushtestvuva();
    print_r($this->file);
}
}
?>

 

Problem renaming starts from 83 to 101 line.

 

Thanks in advance for help.I hope is that you will help me.

Link to comment
https://forums.phpfreaks.com/topic/169111-upload-class-need-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.