使用Dropbox Chooser从Dropbox选取文件后,如何在服务器中存储文件 [英] How can I store the files in my server after picking the files from dropbox with the dropbox Chooser

查看:101
本文介绍了使用Dropbox Chooser从Dropbox选取文件后,如何在服务器中存储文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上有一个表格。表单允许用户从本地计算机中选择文件,或者从下拉框中选择文件。
我知道如何从本地计算机获取文件,然后通过做一些PHP东西将其存储在服务器中。

I have a form in my site. The forms allows the users either to select the files from their local machine or select the files from the drop box. I know how to get a file from the local machine and then store it in the server by doing and with a little bit of PHP stuff.

一项关于保管箱的研究,发现他们做了一个叫做选择器-投保箱的东西。 (基本上,它是一个小的JavaScript组件,使我们的Web应用程序能够从Dropbox获取文件),而且我们可以将 Chooser集成到我们的网络中,这一点非常令人惊奇。

I did a research on drop box and found out that they have made something called 'Chooser - Dropbox'. (Basically, its a small JavaScript component that enables our web-app to get files from Dropbox ) and its pretty amazing that we can integrate 'Chooser' in our web.

但是我的问题是,在使用选配器从Dropbox中选取文件后,我不知道如何将文件存储在服务器中。 (我基本上想下载该文件,然后从Chooser中选择文件,然后存储在我的服务器中)。

But my problem is, I don't know how to store the files in my server after picking the files from dropbox with its Chooser. (I basically want to download that file and store in my server after picking the file from Chooser)

这是DropBox希望我们将其放入网络中的Java脚本的选择器的工作

Here is the java-script that DropBox wants us to put in our web for the working of Chooser

<script type="text/javascript" src="https://www.dropbox.com/static/api/1/dropins.js" id="dropboxjs" data-app-key="aeujnjf6pvgjbst"></script>  

这里是代码。 (PHP用于存储本地计算机上的文件)

Here is the code. (PHP to store files from local machine)

if(isset($_POST) && empty($_POST) == false){
    $file_name = $_POST['file_name'];

    //to store the files selected from local machine
    $file_local = $_FILES['file_local']['name'];
    $file_temp = $_FILES['file_local']['tmp_name'];
    move_uploaded_file($file_temp, 'localhost/projects/');

    //to store the files selected from dropbox
    $file_dropbox = ------ //This is where I am stuck and dont know what to do next

这是以下形式:

<form action="" method="post" enctype="multipart/form-data">
    <input type="text" name="file_name" />
    <input type="file" name="file_local" />

    <!-- input block from dropBox.  -->
    <input type="dropbox-chooser"  data-multiselect="true" data-link-type="direct" name="file_dropbox" style="visibility: hidden;"/>

    <input type="submit" value="upload files">
</form>


推荐答案

在服务器上得到的是逗号分隔的URL列表,位于名为选定文件的字段中。

What you'll get on the server is a comma-delimited list of URLs in a field named "selected-file".

所以 $ _ POST ['selected-file'] 应该类似于 http://example.com/first/url,http://example.com/second/url 。您需要按逗号分隔列表,从给定的URL下载每个文件,然后将它们保存到磁盘。

So $_POST['selected-file'] should look like http://example.com/first/url, http://example.com/second/url. You'll need to split the list on commas, download each file from the given URL, and save them to disk.

编辑

这是一个完整的PHP示例,用于下载通过Chooser选择的多个文件。确保输入您自己的Drop-ins应用程序密钥:

Here's a complete working PHP sample to download multiple files selected via the Chooser. Be sure to enter your own Drop-ins app key:

<!doctype html>
<html>
<head>
    <script type="text/javascript" src="https://www.dropbox.com/static/api/1/dropins.js" id="dropboxjs" data-app-key="<YOUR APP KEY>"></script>
</head>
<body>
    <form method="post">
        <input type="dropbox-chooser" name="selected-file" style="visibility: hidden" data-multiselect="true" data-link-type="direct" />
        <input type="submit" />
    </form>
</body>
</html>

<?php

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    foreach (explode(', ', $_POST['selected-file']) as $url) {
        $curl = curl_init($url);
        $file = fopen(basename($url), 'wb');
        curl_setopt($curl, CURLOPT_FILE, $file);
        curl_setopt($curl, CURLOPT_HEADER, 0);
        curl_exec($curl);
        curl_close($curl);
        fclose($file);
    }
}

?>

这篇关于使用Dropbox Chooser从Dropbox选取文件后,如何在服务器中存储文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆