<i id='3vszT'><tr id='3vszT'><dt id='3vszT'><q id='3vszT'><span id='3vszT'><b id='3vszT'><form id='3vszT'><ins id='3vszT'></ins><ul id='3vszT'></ul><sub id='3vszT'></sub></form><legend id='3vszT'></legend><bdo id='3vszT'><pre id='3vszT'><center id='3vszT'></center></pre></bdo></b><th id='3vszT'></th></span></q></dt></tr></i><div id='3vszT'><tfoot id='3vszT'></tfoot><dl id='3vszT'><fieldset id='3vszT'></fieldset></dl></div>

    • <bdo id='3vszT'></bdo><ul id='3vszT'></ul>

    <legend id='3vszT'><style id='3vszT'><dir id='3vszT'><q id='3vszT'></q></dir></style></legend>

      <small id='3vszT'></small><noframes id='3vszT'>

      <tfoot id='3vszT'></tfoot>
    1. PHP - 将文件移动到服务器上的不同文件夹中

      时间:2023-07-15

      <legend id='wDyOA'><style id='wDyOA'><dir id='wDyOA'><q id='wDyOA'></q></dir></style></legend>
      <tfoot id='wDyOA'></tfoot>
        <tbody id='wDyOA'></tbody>
      • <i id='wDyOA'><tr id='wDyOA'><dt id='wDyOA'><q id='wDyOA'><span id='wDyOA'><b id='wDyOA'><form id='wDyOA'><ins id='wDyOA'></ins><ul id='wDyOA'></ul><sub id='wDyOA'></sub></form><legend id='wDyOA'></legend><bdo id='wDyOA'><pre id='wDyOA'><center id='wDyOA'></center></pre></bdo></b><th id='wDyOA'></th></span></q></dt></tr></i><div id='wDyOA'><tfoot id='wDyOA'></tfoot><dl id='wDyOA'><fieldset id='wDyOA'></fieldset></dl></div>
      • <small id='wDyOA'></small><noframes id='wDyOA'>

            <bdo id='wDyOA'></bdo><ul id='wDyOA'></ul>
                本文介绍了PHP - 将文件移动到服务器上的不同文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我需要允许我网站上的用户在上传图片后从服务器上删除他们不再需要的图片.我以前在 PHP 中使用 unlink 函数,但后来被告知这可能非常危险并且是一个安全问题.(以前的代码如下:)

                I need to allow users on my website to delete their images off the server after they have uploaded them if they no longer want them. I was previously using the unlink function in PHP but have since been told that this can be quite risky and a security issue. (Previous code below:)

                if(unlink($path.'image1.jpg')){ 
                     // deleted
                }
                

                相反,我现在只想将文件移动到不同的文件夹中.这必须能够在他们第一次上传文件后的很长时间内完成,以便他们登录他们的帐户时.如果我有存储用户图像的主文件夹:

                Instead i now want to simply move the file into a different folder. This must be able to be done a long time after they have first uploaded the file so any time they log into their account. If i have the main folder which stores the users image(s):

                user/
                

                然后在名为 del 的文件夹中放置不需要的图像:

                and then within that a folder called del which is the destination to put their unwanted images:

                user/del/
                

                是否有将文件移动到不同文件夹的命令?所以说:

                Is there a command to move a file into a different folder? So that say:

                user/image1.jpg
                

                移动到/变成

                user/del/image1.jpg
                

                推荐答案

                rename 函数就是这样做的

                文档重命名

                rename('image1.jpg', 'del/image1.jpg');

                如果您想将现有文件保留在同一位置,您应该使用 copy

                If you want to keep the existing file on the same place you should use copy

                文档副本

                copy('image1.jpg', 'del/image1.jpg');

                如果你想移动一个上传的文件,使用 move_uploaded_file,虽然这和 rename 几乎一样,这个函数还会检查给定的文件是通过 POST 上传,这可以防止例如移动本地文件

                If you want to move an uploaded file use the move_uploaded_file, although this is almost the same as rename this function also checks that the given file is a file that was uploaded via the POST, this prevents for example that a local file is moved

                文档 move_uploaded_file

                $uploads_dir = '/uploads';
                foreach ($_FILES["pictures"]["error"] as $key => $error) {
                    if ($error == UPLOAD_ERR_OK) {
                        $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
                        $name = $_FILES["pictures"]["name"][$key];
                        move_uploaded_file($tmp_name, "$uploads_dir/$name");
                    }
                }
                

                来自文档的代码片段

                这篇关于PHP - 将文件移动到服务器上的不同文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:HTTP Post 参数通过 json 编码到 $_POST 下一篇:如何使用 PHP 检查目录是否为空?

                相关文章

                    <bdo id='4FW9l'></bdo><ul id='4FW9l'></ul>

                    <small id='4FW9l'></small><noframes id='4FW9l'>

                    <i id='4FW9l'><tr id='4FW9l'><dt id='4FW9l'><q id='4FW9l'><span id='4FW9l'><b id='4FW9l'><form id='4FW9l'><ins id='4FW9l'></ins><ul id='4FW9l'></ul><sub id='4FW9l'></sub></form><legend id='4FW9l'></legend><bdo id='4FW9l'><pre id='4FW9l'><center id='4FW9l'></center></pre></bdo></b><th id='4FW9l'></th></span></q></dt></tr></i><div id='4FW9l'><tfoot id='4FW9l'></tfoot><dl id='4FW9l'><fieldset id='4FW9l'></fieldset></dl></div>
                  1. <legend id='4FW9l'><style id='4FW9l'><dir id='4FW9l'><q id='4FW9l'></q></dir></style></legend>
                  2. <tfoot id='4FW9l'></tfoot>