abstrak:/* * 獲取遠程文件保存本地并獲取相關信息 * @p $src 遠程文件路徑 * @p $localPath 本地保存文件路徑 * @p $ext &nb
/* * 獲取遠程文件保存本地并獲取相關信息 * @p $src 遠程文件路徑 * @p $localPath 本地保存文件路徑 * @p $ext 本地保存文件后綴 * return array*/ function get_file_info($src,$localPath='test',$ext='.html'){ $str = file_get_contents($src); $filePath = $localPath.$ext; if(!file_put_contents($filePath,$str)){ return '文件獲取失敗'; } $kong=array(); $kong['fileType']=filetype($filePath); $kong['fileSize']=filesize($filePath); $kong['ctime']=date('Y-m-d H:i:s',filectime($filePath)); $kong['mtime']=date('Y-m-d H:i:s',filemtime($filePath)); $kong['atime']=date('Y-m-d H:i:s',fileatime($filePath)); $kong['paths']=pathinfo($filePath); return $kong; } //$re = get_file_info('http://img.php.cn/upload/avatar/000/000/001/8dd18f1e1ae4907a738fd106ac717c87.png','img','.png'); //var_dump($re); /* * 向文件添加內(nèi)容 * @p $src 源文件路徑 * @p $content 添加內(nèi)容 * @p $flag 是否覆蓋 * return string * */ function file_add($src,$content,$flag=false){ if(!file_exists($src)) return '文件不存在'; if($content=='') return '添加內(nèi)容不能為空'; if(is_array($content)||is_object($content)) $content=json_encode($content); if(!$flag){ if(file_put_contents($src,$content)) return'內(nèi)容覆蓋成功'; return '內(nèi)容覆蓋失敗'; }else{ $content = "\r\n".$content; if(file_put_contents($src,$content,FILE_APPEND)) return'內(nèi)容添加成功'; return '內(nèi)容添加失敗'; } } echo file_add('text3.csv','ss',true);
Guru membetulkan:韋小寶Masa pembetulan:2019-03-10 13:04:54
Rumusan guru:寫的很不錯 在以后的日常開發(fā)中有很多東西會用到這些相關的函數(shù) 一定要沒事多去練習練習