I was wondering why the for loop won't cycle through the $_files in this php code:
<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);
}
}
}
?>
In this code I use dropbox to upload files always to my account. But will this dropbox method actually help to not slow down my website since it still uses some kind of tmp folder. Is this tmp folder on my website or on the clients pc?
Try checking count($_FILES) instead of count($_FILES['upload']['name']).