I've got a troubles with a file uploading. I'm trying to upload a png file and everything seems OK, but the file is corrupted. I cannot open it in any viewer after download from a FTP server.
Any ideas?
I've tryied these with following results:
- use move_uploaded_file() only to local server dir - the file isn't corrupted
get the file from the ftp by shell command -> the file is corrupted
get the file from the ftp by ftp_get to server dir, then to my machine -> file is OK
get the file by a link (script takes care about getting from FTP and wrap it into the HTTP message) -> corrupted
Code: Select all
public static function saveMultiple($files,$addr){
//echo "dsad";
$result = array();
$addr = ereg_replace(' ','_',$addr);
$addr = ereg_replace('/','_',$addr);
$cn = ftp_connect(self::RES_LIBRARY);
//print_r($files);
if(!$cn) return false;
if(!ftp_login($cn,self::FTP_USER,self::FTP_PSSWD)) return false;
foreach($files as $key => $f){
if($f['size'] == 0) continue;
if(!ftp_chdir($cn,self::FTP_ADDR)) {
if(!ftp_mkdir($cn,self::FTP_ADDR)) return false;
ftp_chdir($cn,self::FTP_ADDR);
};
if(!ftp_chdir($cn,self::FTP_ADDR.$addr)) {
if(!ftp_mkdir($cn,self::FTP_ADDR.$addr)) return false;
ftp_chdir($cn,self::FTP_ADDR.$addr);
};
$x = ftp_nlist($cn,self::FTP_ADDR.$addr);
//var_dump($x);
$ne = true;
foreach($x as $y){
$y = explode("/",$y);
if($y[count($y)-1] == $f['name']) { $ne = false;break; };
};
$file_name = $f['name'];
if(!$ne){
$file_name = explode(".",$file_name,2);
$file_name = $file_name[0].time().'.'.$file_name[1];
};
//echo file_get_contents($f['tmp_name']);
//die();
move_uploaded_file($f['tmp_name'],self::LOCAL_TMP);
////sleep(1);
$res = ftp_put($cn,self::FTP_ADDR.$addr.'/'.$file_name,self::LOCAL_TMP,FTP_BINARY);
//die();
//var_dump($res);
if(!$res) return false;
//var_dump($res);
//echo "dsadas";
$result[] = $addr."/".$file_name;
};
ftp_close($cn);
return $result;
}