0

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';

?>

2 Answers 2

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:

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I've tried to modify the .js in order to both order the list and add the dropbox api without too much success, I'm a noob in .js coding. Can you give me some help to solve it?
0
  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

1 Comment

And then, what I have to do? I need the up folder in the script being a dropbox folder

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.