我可以移动两个文件夹的文件吗?滴点.js

我的拖放区表单


<div align="center">

    <button class="btn btn-success" id="add" onclick='add_img()'>Adicionar imagens <i class="lni-check-mark-circle"></i></button>

</div>

<span  id="menos_img"></span>

<span style="display: none;" id="mais_img">

    <div class="m-auto">

        <form action="clients_images_update.php" style="min-height: 0px;" method="POST" class="dropzone">

            <input type="hidden" name="clients_id" value="<?php echo $id; ?>">

            <input type="hidden" name="users_id" value="<?php echo $_SESSION["user"]["id"]; ?>" />

        </form>

        <div align="center">

            <br>

            <button class="btn btn-success" onClick="window.location.reload();">Atualizar <i class="lni-check-mark-circle"></i></button>

            <button class="btn btn-secondary" onClick="cancela();">Cancelar <i class='lni-cross-circle'></i></i></button>

        </div>          

    </div>

</span>

我的上传文件:


if(!empty($_FILES)) {

    $fileName = $_FILES['file']['name'];

    $source_path = $_FILES['file']['tmp_name'];

    $fileExtension = pathinfo($fileName, PATHINFO_EXTENSION);

    $targetFile = $id."_".$fileName;

    //$targetFile   = $id."_".strtotime("now").$fileName;

    $target_path = "img/clients/".$targetFile;


    $array["filename"] = $targetFile;

    $array["main"] = (int)($db->query("SELECT * FROM images WHERE clients_id = :clients_id;", array("clients_id" => $id), false) == 0);

    $array["clients_id"] = $id;



    if(move_uploaded_file($source_path, $target_path)) {

        $db->insert("images", $array);

    }

    $db->insert("log", array("action" => "image", "inserted_on" => date("Y-m-d H:i:s"), "users_id" => $_POST["users_id"], "clients_id" => $id));

}


波斯汪
浏览 71回答 1
1回答

弑天下

首先,让我们看看你做错了什么:// You're moving the original file right here, this is fineif(move_uploaded_file($source_path, $target_path)) {&nbsp; &nbsp; $db->insert("images", $array);}// This won't work, because you're trying to access orginal file (moved already)image::resize($source_path, "img/clients/thumbs/".$targetFile, 100, 100);$db->insert("log", array("action" => "image", "inserted_on" => date("Y-m-d&nbsp;&nbsp; &nbsp; H:i:s"), "users_id" => $_POST["users_id"], "clients_id" => $id));&nbsp; &nbsp;&nbsp;// Now you're trying to move again the original fileif(move_uploaded_file($source_path, $target_path1)) {&nbsp; &nbsp; echo "Success";}然后,逻辑更简单:首先:如果有文件,请将其移动到目标位置,并保留该文件,无需修改第二:创建拇指并将其保存在其相应的文件夹中,您无需复制,因为文件已经存在if(!empty($_FILES)) {&nbsp; &nbsp; $fileName = $_FILES['file']['name'];&nbsp; &nbsp; $source_path = $_FILES['file']['tmp_name'];&nbsp; &nbsp; $fileExtension = pathinfo($fileName, PATHINFO_EXTENSION);&nbsp; &nbsp; $targetFile = $id."_".$fileName;&nbsp; &nbsp; $target_path = "img/clients/".$targetFile;&nbsp; &nbsp; $array["filename"] = $targetFile;&nbsp; &nbsp; $array["main"] = (int)($db->query("SELECT * FROM images WHERE clients_id = :clients_id;", array("clients_id" => $id), false) == 0);;&nbsp; &nbsp; $array["clients_id"] = $id;&nbsp; &nbsp; // Move original file&nbsp; &nbsp; if(move_uploaded_file($source_path, $target_path)) {&nbsp; &nbsp; &nbsp; &nbsp; $db->insert("images", $array);&nbsp; &nbsp; &nbsp; &nbsp; // Create thumb only if the file was moved, otherwhise you'll get errors&nbsp; &nbsp; &nbsp; &nbsp; // Your source is the file moved, not the one on temp folder&nbsp; &nbsp; &nbsp; &nbsp; image::resize($target_path, "img/clients/thumbs/".$targetFile, 100, 100);&nbsp; &nbsp; &nbsp; &nbsp; $db->insert("log", array("action" => "image", "inserted_on" => date("Y-m-d&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; H:i:s"), "users_id" => $_POST["users_id"], "clients_id" => $id));&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP