<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 - 将文件移动到服务器上的不同文件夹中

      PHP - Move a file into a different folder on the server(PHP - 将文件移动到服务器上的不同文件夹中)

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

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                      <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>
                        • <legend id='4FW9l'><style id='4FW9l'><dir id='4FW9l'><q id='4FW9l'></q></dir></style></legend>
                            <tbody id='4FW9l'></tbody>
                        • <tfoot id='4FW9l'></tfoot>