PHP creates a new file in a loop, moves the file to the specified folder according to the file name, and modifies the file name.

WBOY
Release: 2016-07-28 08:28:23
Original
1179 people have browsed it

Write a php file and put it in the file directory you want to batch process, and run the file to complete
Note: Make sure your file name is a timestamp, and the php file in the file must be judged! Don’t delete it by mistake!

<code>    set_time_limit(<span>0</span>); <span>//忽略php.ini设置的脚本运行时间限制 </span><span>$q_array</span> = my_dir(<span>'./'</span>);
    <span>$q_array</span> = str_replace(<span>'.//'</span>,<span>''</span>,<span>$q_array</span>);
    <span>$a</span> = explode(<span>","</span>,<span>$q_array</span>);
    <span>echo</span><span>"文件目录中的文件数组</br>"</span>;
    var_dump(<span>$a</span>);

    forEd(<span>$a</span>);<span>//修改文件名</span><span>//循环建立新的文件根据时间戳移动文件到指定文件夹修改名称</span><span><span>function</span><span>forEd</span><span>(<span>$arr</span>)</span>{</span><span>$dir</span> = <span>array</span>();
        <span>foreach</span>(<span>$arr</span><span>as</span><span>$v</span>){
            <span>$dir</span>[] = substr(<span>$v</span>,<span>0</span>,<span>6</span>);
        }
        <span>foreach</span>(<span>$arr</span><span>as</span><span>$v</span>){
            <span>$newDir</span> = substr(<span>$v</span>,<span>0</span>,<span>6</span>);

                <span>foreach</span>(<span>$dir</span><span>as</span><span>$v2</span>){
                    <span>if</span>(<span>$v2</span> == <span>$newDir</span>){
                        mk_dir(<span>$newDir</span>);
                        @!copy(<span>$v</span>,<span>$newDir</span>.<span>'/'</span>.substr(<span>$v</span>,<span>6</span>));
                    }
                }

        }
        <span>return</span><span>true</span>;
    }</code>
Copy after login
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above has introduced how PHP loops to create new files, move files to specified folders and modify file names according to file names, including the following aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!