File-upload: how to upload files in an external cloud folder javascript modification

戏子无情 提交于 2020-01-06 14:53:01

问题


I have this .js in order to upload a file and show a list of the uploaded files. I have 2 problems:

  1. How can I show the listed files not in alphabetical but in order of upload?
  2. I know it's possible to load these files in a dropbox or drive folder instead of in a folder in the server, how can I do this?

Thanks

<!DOCTYPE html>
<html>
<body>
<form action="" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
<?php
if (isset($_POST['submit'])) 
{
echo 'succesfully uploaded';
$structure = 'uploadedfiles/';
$target_file = $structure.basename($_FILES["fileToUpload"]["name"]);
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
}
$dir    = 'up/';
$files = scandir($dir);
echo '<h1>List of Uploaded Files</h1> <br><hr>';
$i = 1;
foreach ($files as $key) 
{
    if ($i>3) 
    {
    $j = $i-3;
    echo $j."<a href='up/".$key."'>".$key."</a><hr>";
    }
    $i++;

}
echo 'End of Files';

?>

回答1:


  1. If you're referring to the list of files shown on your own site, you'll want to maintain the desired order in some persistent list somewhere, or sort them based on whatever criteria you want, before showing the list of files to the user. (E.g., based on the modified time from the filesystem, etc.)

  2. To upload files to Dropbox programmatically, you'll need to use the Dropbox API:

https://www.dropbox.com/developers/core

There's an official PHP SDK here:

  • download
  • tutorial
  • documentation



回答2:


  1. Click the modified filter in Dropbox(Web)
  2. Right click the file you want to use and selected url. It is gonna be something like this:

    https://www.dropbox.com/s/6fk1231mvp9idx7/cos.rar?dl=0

replace www with dl. It is gonna be something like this:

https://dl.dropbox.com/s/6fk1231mvp9idx7/cos.rar?dl=0


来源:https://stackoverflow.com/questions/30675159/file-upload-how-to-upload-files-in-an-external-cloud-folder-javascript-modifica

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!