在文本框中保存了一些图片的地址,要将它生成txt文件保存到本地,怎么做哦!给点例子啊,还有解释

解决方案 »

  1.   

    function write2file($msg,$fileName)
    {
        $fp = @fopen($fileName, 'a');
        if($fp==false)
        {
            $fp=@fopen($fileName,'w+');
            if($fp==false)
            {
                
                echo " file ".$fileName." can not be created for writing";
                return 0;
                
            }
        }
        $lfp = flock($fp,LOCK_EX);
        $i = 0;
        while ($lfp == False)
        {
            $i++;
            $lfp = flock($fp,LOCK_EX);
            if ($i==10){return(0);}
        }
        fputs($fp,$msg);
        flock($fp,LOCK_UN);
        fclose($fp);
        return 1;
    }
      

  2.   

    $msg是接收的文本框中的值
    $fileName是你要放的txt文本的文件路径
      

  3.   

    好了啊,谢谢各位,发个源码大家在给点建议。
    if($mesh->post["type"]=="1")//存储文件。
    {
    $model=1;
    require_once('splash/model'.$model.'/model.php');
    $data= $mesh->db->FindById('net_splash',$netid,"netid");
    $mode= new model();

    $html=$mode->parse_echo($data->content);////////////////////////////////////////////////////
    saveFiles(SPLASH_DIR.$netid.".txt",$html);//保存splash页面的html代码,

    $cmd=array();
    $cmd[]="page ".WWW_URL."splash/".$netid.".txt";
    foreach($mode->images as $value){
    $cmd[]="image ".WWW_URL.$value;
    }
    /*
    * $cmd[]=? 从数据库把用户定义的图片资源拿出来,images/bg.jpg

    */
    $cmd[]="image ".WWW_URL.$data->images;
    saveFiles(SPLASH_DIR.$netid.".page",implode("\r\n",$cmd));//splash.page的所有命令。
    }function saveFiles($filename,$content)
    {
    if($fp = fopen($filename, "w"))
    {
    if(!fwrite($fp,$content,strlen($content)))
    {
    fclose($fp);
    return false;
    }
    fclose($fp);
    return true;
    }else
    return false;
    }
      

  4.   


    首先获取文本框里的内容,再将内容POST到对应的处理程序,再生成文件即可