亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

獲取遠程文件內(nèi)容保存,并獲取文件相關信息;本地文件內(nèi)容添加

原創(chuàng) 2019-03-10 11:21:02 240
摘要:/*  * 獲取遠程文件保存本地并獲取相關信息  * @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)容添加成功';
    }
}
echo file_add('text3.csv','ss',true);


發(fā)布手記

熱門詞條