简体   繁体   中英

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

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. 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. (Eg, 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:

  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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM