dspld86684 2013-07-08 06:14
浏览 29
已采纳

关于此脚本中使用的函数[关闭]

I was making a script for remote upload files to my server and here the code. BTW i took it from a site. I didn't post the site name or it might b considered as spam or something. Its about downloading remote files into our server.

<?php

if (isset($_POST['myupload']))    
{

    $links_list = $_POST['upload'];
    $incr = 0;
    $links = explode("
",$links_list);

    define('BUFSIZ', 4095);

    for ( $incr == 0 ; $incr < count($links) ; $incr++ )
    {
        $url = $links[$incr];
        $rfile = fopen($url, 'r');
        $lfile = fopen(basename($url), 'wb');
        while(!feof($rfile))
            fwrite($lfile, fread($rfile, BUFSIZ), BUFSIZ);
        fclose($rfile);
        fclose($lfile);
    }
}
?> 

    <script type="text/javascript"></script>
</head>    
<body>
    <div id="upload_box">
        <form action="" method="post">   
            <textarea name="upload" cols=80 rows=20></textarea>
            <input type="submit" name="myupload" value="Upload Files">
        </form>

I want to ask few things about this script.

  • $lfile = fopen(basename($url), 'wb') < what does this code do ?

  • fwrite($lfile, fread($rfile, BUFSIZ), BUFSIZ); < and what about this code ?

I know am asking a foolish question but hope you guys could shed some light on that for me.

  • 写回答

3条回答 默认 最新

  • duancong7358 2013-07-08 06:22
    关注
    $lfile = fopen(basename($url), 'wb')
    

    fopen: Function that opens a file and returns a handle that can be used to read/write that file, depending on the second argument (explained below).

    basename: Function that strips the path from the file name, leaving just the name part. For example: basename('http://foo.com/bar.txt') would return bar.txt

    'wb': This tells fopen how to open the file: w means open it for writing, b means open it for binary access, which just means don't do any funky line ending translation (only really useful on Windows).

    $lfile: This is the handle to the file that will be used later to write to it.

    fwrite($lfile, fread($rfile, BUFSIZ), BUFSIZ);
    

    fwrite: Writes data to a previously opened file handle ($lfile in this case)

    fread: Reads data from a file.

    BUFSIZ: I'm assuming this is a constant defined somewhere. Regardless, the 3rd parameter to fwrite specifies how many bytes to write to the file, and the 2nd parameter to fread specifies how many bytes to read. In this case, they are both the same.

    This kind of operation is sometimes known as a buffered or block copy.

    Broken apart it would look something like this:

    $data = fread($rfile, BUFSIZ);
    fwrite($lfile, $data, BUFSIZ);
    

    Hope that helps!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题