没有循环通过$_files数组,这个文件上传方法不会减慢我的网站速度吗


Not looping through $_files array and would this file upload method not slow down my website?

我想知道为什么for循环不会循环通过这个php代码中的$_files:

<html>
    <form action="" method="post">
        Your name: <input type="text" name="name"/><br>
        Select your files: <input type="file" name="upload[]" multiple /><br>
        <input  type="submit" name="submit" value="Send">
    </form>
</html>
<?php
require_once "dropbox-sdk/Dropbox/autoload.php";
use 'Dropbox as dbx;
$dbxClient = new dbx'Client("************", "PHP-Example/1.0");
if(isset($_POST["name"])){
    $dbxClient->createFolder("/" . $_POST["name"]);
    echo "folder created";
    //Loop through each file
    for($i=0; $i<count($_FILES['upload']['name']); $i++) {
        echo "I now looped " . $i . " times<br>";
        //Get the temp file path
        $tmpFilePath = $_FILES['upload']['tmp_name'][$i];
        //check if file exists
        if ($tmpFilePath != ""){
            echo "Loop " . $i . " - file exists<br>";
            //Setup our new file path
            $newFilePath = $_POST["name"] . "/" . $_FILES['upload']['name'][$i];
            //Upload the file to dropbox
            $f = fopen($tmpFilePath, "rb");
            $result = $dbxClient->uploadFile($tmpFilePath, dbx'WriteMode::add(), $f);
            fclose($f);
            print_r($result);
        }
    }
}
?>

在这段代码中,我使用dropbox将文件始终上载到我的帐户。但是这种dropbox方法真的会帮助我的网站不减速吗,因为它仍然使用某种tmp文件夹。这个tmp文件夹是在我的网站上还是在客户端电脑上?

将表单定义更改为:

     <form action="DOSOMETHING.PHP" method="post" enctype="multipart/form-data>

您需要一个操作来处理它,并需要enctype来识别文件。我把PHP放在一个单独的文件DOSOMETHING.PHP中。除此之外,您的表单和PHP循环似乎工作得很好。

尝试检查count($_FILES)而不是count($.FILES['pload']['name'])。

我认为不放慢你的网站速度是没有帮助的。tmp文件夹也是您自己的服务器上的文件夹