php 采集其它服务器文件程序

 更新时间:2016年11月25日 16:26  点击:2149

header("pragma:no-cachern");
  header("cache-control:no-cachern");
  header("expires:0rn");
  $rmurl = "http://www.111cn.net/demodata.txt";
 
 $infostring = file_get_contents($rmurl) or die("连接远程网址失败!");
 $infos = split(',',$infostring);
 $maxnum  =count($infos);
  $rmurl = trim($infos[rand(0,$maxnum-1)]);
 
  $zipbin = file_get_contents($rmurl);
 $fp = fopen(dirname(__file__).'/dedev56demo.zip','w');
 fwrite($fp,$zipbin);
 unset($zipbin);
 fclose($fp);

 

文章提供一款php检测文件类型(根据文件header信息)哦,他可以根据用户发布的文件头部信息来确实文件的类型。
 代码如下 复制代码
<?php
/*通过文件名,获得文件类型*
*@author chengmo*
*@copyright cnblog.com/chengmo 2010-10-17
*@version 0.1
*$filename="d:/1.png";echo cfiletypecheck::getfiletype($filename); 打印:png
*/
class cfiletypecheck
{
private static $_typelist=array();
private static $checkclass=null;
private function __construct($filename)
{
self::$_typelist=$this->gettypelist();
}
/**
*处理文件类型映射关系表*
*
* @param string $filename 文件类型
* @return string 文件类型,没有找到返回:other
*/
private function _getfiletype($filename)
{
$filetype="other";
if(!file_exists($filename)) throw new exception("no found file!");
$file = @fopen($filename,"rb");
if(!$file) throw new exception("file refuse!");
$bin = fread($file, 15); //只读15字节 各个不同文件类型,头信息不一样。
fclose($file);
$typelist=self::$_typelist;
foreach ($typelist as $v)
{
$blen=strlen(pack("h*",$v[0])); //得到文件头标记字节数
$tbin=substr($bin,0,intval($blen)); ///需要比较文件头长度
if(strtolower($v[0])==strtolower(array_shift(unpack("h*",$tbin))))
{
return $v[1];
}
}
return $filetype;
}
/**
*得到文件头与文件类型映射表*
*
* @return array array(array('key',value)...)
*/
public function gettypelist()
{
return array(array("ffd8ffe1","jpg"),
array("89504e47","png"),
array("47494638","gif"),
array("49492a00","tif"),
array("424d","bmp"),
array("41433130","dwg"),
array("38425053","ps教程d"),
array("7b5c727466","rtf"),
array("3c3f786d6c","xml"),
array("68746d6c3e","html"),
array("44656c69766572792d646174","eml"),
array("cfad12fec5fd746f","dbx"),
array("2142444e","pst"),
array("d0cf11e0","xls/doc"),
array("5374616e64617264204a","mdb"),
array("ff575043","wpd"),
array("252150532d41646f6265","eps/ps"),
array("255044462d312e","pdf"),
array("e3828596","pwl"),
array("504b0304","zip"),
array("52617221","rar"),
array("57415645","wav"),
array("41564920","avi"),
array("2e7261fd","ram"),
array("2e524d46","rm"),
array("000001ba","mpg"),
array("000001b3","mpg"),
array("6d6f6f76","mov"),
array("3026b2758e66cf11","asf"),
array("4d546864","mid"));
}
public static function getfiletype($filename)
{
if(!self::$checkclass) self::$checkclass=new self($filename);
$class=self::$checkclass;
return $class->_getfiletype($filename);
}
}
下面我收藏了三php删除文件哦,他可以利用unlink删除任何可删除的文件,本程序要删除文件,图片,压缩文件等,我们利用了几种方法来实例

三种php删除文件代码

 代码如下 复制代码

if($od=opendir($d))   //$d是目录名
{
        while(($file=readdir($od))!==false)  //www.111cn.net 读取目录内文件
        {
        unlink($file);  //$file是文件名
        }
}

去了解下这三个php函数:opendir()  readdir()  unlink()

文件删除代码二 系统调用法

 

 代码如下 复制代码
function del_dir($dir)
{
if(strtoupper(substr(php_os, 0, 3)) == 'win') {
       $str = "rmdir /s/q " . $dir;
} else {
       $str = "rm -rf " . $dir;
}
}

文件删除代码三

 代码如下 复制代码
$info = "a123"; //目录名
if(is_dir($info)){
if(rmdir($info)){
echo "目录{$inof}删除完毕www.111cn.net";
}else{
echo "目录无法删除!原因--可能是目录下还存在文件!";
}
}
if(is_file($info)){
if(unlink($info)){
echo "文件{$info}删除完毕...!";
}else{
echo "文件{$info}mb.111cn.net删除失败...!尝试修改文件权限删除...";
if(chmod($info,0777)){
unlink($info);
echo "文件{$info}权限修改后删除完毕...";
}else{
echo "文件{$info}无法通过web方式删除,可能是ftp权限对此文件有所设置...";
}
}
}

最近发现很多网站转载本站文件,注请加上本站连接,谢谢合作!

提供一款免费的php 问问采集代码哦,如果你正想采集问问,但是又不知道怎么写采集程序,这里为你提供一款经典的问问采集程序哦。
 代码如下 复制代码
<?php
session_start();
header("content-type:text/html;charset=utf-8");
require("stole_config.php");
require("conn.php");
require("keyword.php");
if(!empty($_post['ask']))
{
$ask=urlencode(trim($_post['ask']));//获取表单提交的问题
$sp="s".$ask;
}else
{
$sp=urlencode($_get['sp']);
}
if(empty($_get['jl']))
{
$_get['jl']=1;
}
$jl=$_get['jl'];
$pg=intval($_get['pg']);//获取页数
$rs=intval($_get['rs']);//获得 记录的参数
if($rs>9)
{
$rs=0;
$pg++;
}
if($pg>51)
{
echo "采集完毕! 总共采集 ".urldecode($sp)." ".$jl."条记录";
exit();
}
if($sp)//有设定答案才开始
{
$str=@file_get_contents("http://wenwen.soso.com/z/search.e?sp={$sp}&pg={$pg}");
@preg_match("/<ol class="result_list">(.*)</ol>/ius",$str,$asklist);//获取问答列表
//echo $asklist[1];
$url="/<a target="_blank" href="/z/(q.*.htm)/ius";
@preg_match_all($url,$asklist[1],$urllist);//获取 所有的问题
$t=$urllist[1][$rs];
$uid=$t;
$suid="ww{$uid}";
$sct=mysql教程_query("select count(*) from {$table_prefix}c_article where suid='$suid' ");
$sct=mysql_fetch_array($sct);
$sct=$sct[0];
if($sct==0)
{
$html=@file_get_contents("http://wenwen.soso.com/z/${t}");
$html=str_replace("<pre>","",str_replace("</pre>","",$html));
$html=str_replace("<br/><br/><br/>","<br/><br/>",$html);
//echo $html;
@preg_match("/<div class="question_main">.*<h3>(.*)</h3>/ius",$html,$ask_title);
$art_title=$ask_title[1];
@preg_match("/<div class="answer_con">(.*)</div>/ius",$html,$answer);
$j=count($answer)-1;
$art_content="";//商品详细
for($i=$j;$i>=1;$i--)
{
if(strlen($answer[$i])>$min_t1)
{
$art_content .= $answer[$i];
}
}
$art_content=trim($art_content);
$s1="/(<a .*>)(.*)</a>/ius";
$art_content=preg_replace($s1,${2},trim($art_content));
$word_arr=explode(",",iconv("gbk","utf-8",$cj_word));
$word_allow=false;//初始化是否允许采集
$word_count=count($word_arr);//总数
for($i=0;$i<$word_count;$i++)
{
if(substr_count($art_title,$word_arr[$i])>0)
{
$word_allow=1;
$i=$word_count;
}
}
if($word_allow)//如果合法
{ //开始处理数据库教程
if(strlen($art_content)>$min_t2)
{
echo "<font color=red>添加中............................</font><br>";
echo $art_title."<br>";
$art_title=iconv('utf-8','gbk', $art_title);
$title_ct=mysql_query("select count(*) from {$table_prefix}c_article where art_title ='$art_title' ");//查看标题是否重复
$title_ct=@mysql_fetch_array($title_ct);
$title_ct=$title_ct[0];
if($title_ct>0)
{
$art_title .="{$same_title}{$title_ct}";
}
$art_content=iconv('utf-8','gbk',str_replace(" ","<br>",$art_content));
$art_content=strtr($art_content,$keyword);
$art_time=date("y-m-d");
$sql="insert into {$table_prefix}c_article(art_title,art_content,art_time,art_author,suid) values('$art_title','$art_content','$art_time','$art_author','$suid')";//插入采集表
mysql_query($sql);
if(empty($t_catx_id))//如果无分类
{
$sql2="insert into {$t_table}({$t_art_title},{$t_art_content},{$t_art_time},{$t_artx_author}) values('$art_title','$art_content','$art_time','$art_author')";
}else
{
$sql2="insert into {$t_table}({$t_art_title},{$t_art_content},{$t_art_time},{$t_artx_author},{$t_catx_id}) values('$art_title','$art_content','$art_time','$art_author','$cat_id')";
}
mysql_query($sql2);//插入文章表
$jl++;//如果存放数据库中 则记录加1
//处理数据库结束
}else
{
echo "长度不够";
}
}else
{
echo "主题不符合要求";
}
}else
{
echo "已经存在";
}
$rs++;
//记录下本次采集 的状况
$f_tt= urldecode($sp)."--页数".$pg." 记录数 ".$jl ;
file_put_contents("ss.txt",$f_tt);
echo "<script>location.href='wenwen.php?jl=".$jl."&sp=".$sp."&pg=".$pg."&rs=".$rs." ';</script>";
exit();
}
?>
<link href="style.css教程" rel="stylesheet" type="text/css" />
<table width="700" border="0" align="center" cellspacing="1" bgcolor="#cccccc">
<tr>
<td height="50" align="center" bgcolor="#00cc00"><h1><a href="http://www.111cn.net">荐礼啦</a>知道问问采集插件</h1></td>
</tr>
</table>
<table width="700" border="0" align="center" cellspacing="1" bgcolor="#cccccc" style="margin-top:6px; margin-bottom:6px;">
<tr>
<td height="30" align="center" bgcolor="#ffffff"><a href="cj_config.php">采集设置</a> <a href="uninstall.php" onclick="return confirm('您确定要卸载采集插件吗');">卸载采集</a> <a href="cj_view.php">查看采集记录</a> <a href="cj_help.php">采集帮助</a> <a href="baidu.php" target="_blank">知道采集</a> <a href="wenwen.php" target="_blank">问问采集</a></td>
</tr>
</table>
<form action="wenwen.php" method="post">
<table width="628" height="49" border="0" align="center">
<tr>
<td width="413" align="right"><input name="ask" type="text" id="ask" size="50"></td>
<td width="205"><input type="submit" name="button" id="button" value="问问采集" style=" padding-left:15px; padding-right:15px; height:25px; line-height:25px;"></td>
</tr>
</table>
</form>
一款实例的php图片加水印,切头像图和自动缩放代码,他可以把你上传的图片生成指定大小的效果图与可以对图片进行自动切剪,下面看实例。
 代码如下 复制代码

<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=gb2312">
  <meta name="author" content="verdana core, phpdoc.net inc.">
  <title>上传文件测试</title>
  </head>
<body>
  <form method=post  enctype="multipart/form-data" action="<?php echo url_for("upload/webimages",true);?>">
  <input type="file" name="upload" id="upload" onchange="preview()"; />
  <br /><br />
  <input type="submit" value="上传图片">
  </form>
  </body>
</html>

http://code.google.com/p/queryphp/downloads/list

frameworklibimg.class.php中的img类

<?
/*
php图片加水印,切头像图和自动缩放代码

*/

class uploadrouter extends controller{
  function index()
  {
    //输出上传表单,详见视图文件
  }
  function webimages()
  {
    print_r($_files);
    $img=c("img");
    $img->setinfo(  //设置上传文件属性
          array("files"=>"upload", //上传文件框名name
                "uploadpath"=>$globals['config']['webprojectpath']."upimages/", //上传目录
                "icopath"=>$globals['config']['webprojectpath']."upimages/",    //小图目录 如果不设置将是使用上传目录            
                "icowidth"=>"128",  //小图宽
                "icoheight"=>"98",  //小图高
                "fangpath"=>$globals['config']['webprojectpath']."upimages/_ico/", //切方图,就是切头像等
                "fangsize"=>"75", //方图多大 如果设置了切方图那么上传时候会生成切方图,不要可以不设置
                "nzsize"=>"180",   //自动设置宽或高不超这个
                "uploadsize"=>420000 //上传图片大小
                )
          )->setbasename($_files['upload']['name'],true)->init();//,'size_ico','auto_ico','fix_ico','fill_size''fix_side'
         //可以自己设置setbasename名不然会自动生成日期名字,其中会自动把中文换掉成拼音和过滤最后初始化init()
         //初始化完毕,可以上传了
    if($img->upload(array('fix_side'))) //上传了,设置要不要生成小图。有多种格式 如果是空那么只上传图片其它不理。
    {
      echo("上传成功");
    }else{
      echo("上传失败");
      echo $img->message;
    }
    return false;
  }
}


?>

[!--infotagslink--]

相关文章

  • php读取zip文件(删除文件,提取文件,增加文件)实例

    下面小编来给大家演示几个php操作zip文件的实例,我们可以读取zip包中指定文件与删除zip包中指定文件,下面来给大这介绍一下。 从zip压缩文件中提取文件 代...2016-11-25
  • Jupyter Notebook读取csv文件出现的问题及解决

    这篇文章主要介绍了JupyterNotebook读取csv文件出现的问题及解决,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2023-01-06
  • Photoshop打开PSD文件空白怎么解决

    有时我们接受或下载到的PSD文件打开是空白的,那么我们要如何来解决这个 问题了,下面一聚教程小伙伴就为各位介绍Photoshop打开PSD文件空白解决办法。 1、如我们打开...2016-09-14
  • C#操作本地文件及保存文件到数据库的基本方法总结

    C#使用System.IO中的文件操作方法在Windows系统中处理本地文件相当顺手,这里我们还总结了在Oracle中保存文件的方法,嗯,接下来就来看看整理的C#操作本地文件及保存文件到数据库的基本方法总结...2020-06-25
  • 解决python 使用openpyxl读写大文件的坑

    这篇文章主要介绍了解决python 使用openpyxl读写大文件的坑,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-13
  • C#实现HTTP下载文件的方法

    这篇文章主要介绍了C#实现HTTP下载文件的方法,包括了HTTP通信的创建、本地文件的写入等,非常具有实用价值,需要的朋友可以参考下...2020-06-25
  • SpringBoot实现excel文件生成和下载

    这篇文章主要为大家详细介绍了SpringBoot实现excel文件生成和下载,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-02-09
  • php无刷新利用iframe实现页面无刷新上传文件(1/2)

    利用form表单的target属性和iframe 一、上传文件的一个php教程方法。 该方法接受一个$file参数,该参数为从客户端获取的$_files变量,返回重新命名后的文件名,如果上传失...2016-11-25
  • php批量替换内容或指定目录下所有文件内容

    要替换字符串中的内容我们只要利用php相关函数,如strstr,str_replace,正则表达式了,那么我们要替换目录所有文件的内容就需要先遍历目录再打开文件再利用上面讲的函数替...2016-11-25
  • PHP文件上传一些小收获

    又码了一个周末的代码,这次在做一些关于文件上传的东西。(PHP UPLOAD)小有收获项目是一个BT种子列表,用户有权限上传自己的种子,然后配合BT TRACK服务器把种子的信息写出来...2016-11-25
  • AI源文件转photoshop图像变模糊问题解决教程

    今天小编在这里就来给photoshop的这一款软件的使用者们来说下AI源文件转photoshop图像变模糊问题的解决教程,各位想知道具体解决方法的使用者们,那么下面就快来跟着小编...2016-09-14
  • C++万能库头文件在vs中的安装步骤(图文)

    这篇文章主要介绍了C++万能库头文件在vs中的安装步骤(图文),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-02-23
  • Zend studio文件注释模板设置方法

    步骤:Window -> PHP -> Editor -> Templates,这里可以设置(增、删、改、导入等)管理你的模板。新建文件注释、函数注释、代码块等模板的实例新建模板,分别输入Name、Description、Patterna)文件注释Name: 3cfileDescriptio...2013-10-04
  • php文件上传你必须知道的几点

    本篇文章主要说明的是与php文件上传的相关配置的知识点。PHP文件上传功能配置主要涉及php.ini配置文件中的upload_tmp_dir、upload_max_filesize、post_max_size等选项,下面一一说明。打开php.ini配置文件找到File Upl...2015-10-21
  • ant design中upload组件上传大文件,显示进度条进度的实例

    这篇文章主要介绍了ant design中upload组件上传大文件,显示进度条进度的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-10-29
  • C#使用StreamWriter写入文件的方法

    这篇文章主要介绍了C#使用StreamWriter写入文件的方法,涉及C#中StreamWriter类操作文件的相关技巧,需要的朋友可以参考下...2020-06-25
  • php实现文件下载实例分享

    举一个案例:复制代码 代码如下:<?phpclass Downfile { function downserver($file_name){$file_path = "./img/".$file_name;//转码,文件名转为gb2312解决中文乱码$file_name = iconv("utf-8","gb2312",$file_name...2014-06-07
  • 分享一段php获取linux服务器状态的代码

    简单的php获取linux服务器状态的代码,不多说-直接上函数:复制代码 代码如下:function get_used_status(){ $fp = popen('top -b -n 2 | grep -E "^(Cpu|Mem|Tasks)"',"r");//获取某一时刻系统cpu和内存使用情况 $rs =...2014-05-31
  • C#路径,文件,目录及IO常见操作汇总

    这篇文章主要介绍了C#路径,文件,目录及IO常见操作,较为详细的分析并汇总了C#关于路径,文件,目录及IO常见操作,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
  • 查找php配置文件php.ini所在路径的二种方法

    通常php.ini的位置在:复制代码 代码如下:/etc目录下或/usr/local/lib目录下。如果你还是找不到php.ini或者找到了php.ini修改后不生效(其实是没找对),请使用如下办法:1.新建php文件,写入如下代码复制代码 代码如下:<?phpe...2014-05-31