问题
I have this .js
in order to upload a file and show a list of the uploaded files. I have 2 problems:
- How can I show the listed files not in alphabetical but in order of upload?
- 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. (E.g., based on the modified time from the filesystem, etc.)
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:
- Click the
modified
filter in Dropbox(Web) 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