当前位置: 首页>>代码示例>>PHP>>正文


PHP http::savetofile方法代码示例

本文整理汇总了PHP中http::savetofile方法的典型用法代码示例。如果您正苦于以下问题:PHP http::savetofile方法的具体用法?PHP http::savetofile怎么用?PHP http::savetofile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在http的用法示例。


在下文中一共展示了http::savetofile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: thumb

 function thumb($url = '', $source = '', $name = '', $type = -1, $width = 0, $height = 0)
 {
     //如何生成不成功,则返回原url
     global $cms_abs, $cmsurl, $ftp_url, $atm_smallsite;
     if (!$url || !$source || !$name || !$width || !$height) {
         return $url;
     }
     include_once M_ROOT . "./include/upload.cls.php";
     if ($ftp_url && preg_match(u_regcode($ftp_url), $url)) {
         //ftp上的文件
         include_once M_ROOT . "./include/http.cls.php";
         include_once M_ROOT . "./include/ftp.fun.php";
         //下载原图
         $tempfile = M_ROOT . './dynamic/imcache/' . basename($url);
         mmkdir($tempfile, 0, 1);
         $m_http = new http();
         $m_http->savetofile($url, $tempfile);
         unset($m_http);
         //生成缩略图
         $m_upload = new cls_upload();
         $m_upload->image_resize($tempfile, $width, $height, $tempfile . '.s.jpg');
         @unlink($tempfile);
         unset($m_upload);
         //上传缩略图
         $ftpfile = preg_replace(u_regcode($ftp_url), '', $url) . 's/' . $width . '_' . $height . '.jpg';
         //根据url得到缩略上传到的位置
         $tempfile .= '.s.jpg';
         if (ftp_upload($tempfile, $ftpfile)) {
             $this->refresh_record($source, $name, $type, $width, $height);
             //将缩略图规格写入数据库
             return $url . 's/' . $width . '_' . $height . '.jpg';
         } else {
             return $url;
         }
         @unlink($tempfile);
     } else {
         //本地服务器上的文件
         $m_upload = new cls_upload();
         $localfile = local_atm($url);
         $m_upload->image_resize($localfile, $width, $height, $localfile . 's/' . $width . '_' . $height . '.jpg');
         unset($m_upload);
         return $url . 's/' . $width . '_' . $height . '.jpg';
     }
 }
开发者ID:polarlight1989,项目名称:08cms,代码行数:44,代码来源:thumb.cls.php

示例2: array

 function remote_upload($remotefile, $rpid, $jumpfile = '*')
 {
     //jumpfile为允许的跳转文件格式
     //返回数组
     global $rprojects, $curuser, $memberid, $dir_userfile, $db, $tblprefix, $timestamp, $ftp_enabled;
     $result = array('remote' => $remotefile);
     if (!$this->capacity) {
         return $result;
     }
     if (empty($rpid) || empty($rprojects[$rpid]['rmfiles'])) {
         return $result;
     }
     if (islocal($remotefile, 1)) {
         return $result;
     }
     if (!empty($rprojects[$rpid]['excludes'])) {
         foreach ($rprojects[$rpid]['excludes'] as $k) {
             if (in_str($k, $remotefile)) {
                 return $result;
             }
         }
     }
     $rmfiles = $rprojects[$rpid]['rmfiles'];
     $extension = strtolower(mextension($remotefile));
     if (in_array($extension, array_keys($rmfiles))) {
         $rmfile = $rmfiles[$extension];
     } else {
         return $result;
     }
     $uploadfile = array();
     $uploadfile['mid'] = $curuser->info['mid'];
     $uploadfile['mname'] = $curuser->info['mname'];
     $file_saved = false;
     $uploadfile['filename'] = preg_replace("/(php|phtml|php3|php4|jsp|exe|dll|asp|cer|asa|shtml|shtm|aspx|asax|cgi|fcgi|pl)(\\.|\$)/i", "_\\1\\2", date('dHis') . substr(md5($remotefile . microtime()), 5, 10) . random(4, 1) . '.' . $rmfile['extname']);
     $uploadpath = $this->upload_path($rmfile['ftype']);
     $uploadfile['url'] = $uploadpath . $uploadfile['filename'];
     $target = M_ROOT . $uploadpath . $uploadfile['filename'];
     @chmod($target, 0644);
     $m_http = new http();
     if ($rprojects[$rpid]['timeout']) {
         $m_http->timeout = $rprojects[$rpid]['timeout'];
     }
     $file_saved = $m_http->savetofile($remotefile, $target, $rmfile['maxsize']);
     unset($m_http);
     if (!$file_saved) {
         @unlink($target);
         return $result;
     }
     if (filesize($target) < $rmfile['minisize'] * 1024) {
         @unlink($target);
         return $result;
     }
     $uploadfile['size'] = filesize($target);
     if (in_array($rmfile['extname'], array('jpg', 'jpeg', 'gif', 'png', 'swf', 'bmp'))) {
         //图片或是flash
         if (!($infos = @getimagesize($target))) {
             @unlink($target);
             return $result;
         }
         if (in_array($rmfile['extname'], array('jpg', 'jpeg', 'gif', 'png', 'bmp'))) {
             if ($this->image_watermark($target)) {
                 $uploadfile['size'] = filesize($target);
             }
             $uploadfile['width'] = $infos[0];
             $uploadfile['height'] = $infos[1];
         }
     }
     if ($ftp_enabled) {
         include_once M_ROOT . "./include/ftp.fun.php";
         ftp_upload($target, $uploadfile['url']);
     }
     $this->upload_size += ceil($uploadfile['size'] / 1024);
     if ($this->capacity != -1) {
         $this->capacity -= ceil($uploadfile['size'] / 1024);
         $this->capacity = max(0, $this->capacity);
     }
     $db->query("INSERT INTO {$tblprefix}userfiles SET\n\t\t\t\t\tfilename='{$uploadfile['filename']}',\n\t\t\t\t\turl='{$uploadfile['url']}',\n\t\t\t\t\ttype='{$rmfile['ftype']}',\n\t\t\t\t\tcreatedate='{$timestamp}',\n\t\t\t\t\tmid='{$uploadfile['mid']}',\n\t\t\t\t\tmname='{$uploadfile['mname']}',\n\t\t\t\t\tsize='{$uploadfile['size']}'\n\t\t\t\t\t");
     if ($ufid = $db->insert_id()) {
         $this->ufids[] = $ufid;
     }
     $result['remote'] = $uploadfile['url'];
     $result['size'] = $uploadfile['size'];
     if (isset($uploadfile['width']) && isset($uploadfile['height'])) {
         $result['width'] = $uploadfile['width'];
         $result['height'] = $uploadfile['height'];
     }
     unset($uploadfile);
     return $result;
 }
开发者ID:polarlight1989,项目名称:08cms,代码行数:89,代码来源:upload.cls.php


注:本文中的http::savetofile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。