andreashp / php-mime-mail-parser

Automatically exported from code.google.com/p/php-mime-mail-parser
0 stars 0 forks source link

File Name Change #36

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.Send any attachment with the same name

What is the expected output? What do you see instead?
The system should change the file name. The system overwrites existing files 
with the same name.  

Please provide any additional information below.
I added the following function to the system to fix the issue. I am still 
learning so the code may not be perfect, but it works great.

public function checkFileName($filename){
    $fullFileName = dirname( __FILE__ ).'/save_dir/'.$filename;
    if(file_exists($fullFileName)){
        $exists='1';$check='';
        $splitFile = explode('.',$filename);
        $count = count($splitFile);
        $counter = $count-1;;
        $piece = $splitFile[$counter];
        $file='';
        for($i=0;$i<$count-1;$i++){
            $file.=$splitFile[$i];
        }
        $i='1';
        while($exists='1'){
            $check = $file.'('.$i.').'.$piece;
            $name=dirname( __FILE__ ).'/save_dir/'.$check;
            if(!file_exists($name)){break;}
            else{$i++;}
        }
        $filename=$check;
    }
    return $filename;
}

Original issue reported on code.google.com by i...@cwdgservices.com on 24 Apr 2013 at 6:02