# upload\_file()

## Upload a file

&#x20; <mark style="background-color:orange;">upload()</mark> &#x20;

Upload a file to the cloud using a simple file object.

{% tabs %}
{% tab title="OneDrive" %}

### **Parameters**

<table><thead><tr><th width="232">Name</th><th width="93">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>$file</code></td><td>File object</td><td>Object containing the file details. Same as file object in <code>$_FILES</code>.</td></tr><tr><td><code>$upload_folder_id</code></td><td>string</td><td>ID of the upload folder.</td></tr><tr><td><code>$description</code></td><td>string</td><td>Description for the file.</td></tr><tr><td><code>$overwrite</code></td><td>bool</td><td>Overwrite an existing file with the same name? If false, the file will be renamed.</td></tr></tbody></table>

### **Return**

<table><thead><tr><th width="194">Name</th><th width="166">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>$node</code></td><td><strong>CachedNode</strong></td><td>The object for the uploaded file.</td></tr></tbody></table>

### **Usage**

```php
WPCP_ONEDRIVE_API::set_account_by_id('8c9bacda0-d8d8-4b22-b634-7b5281687575');
WPCP_ONEDRIVE_API::set_drive_by_id('b!DlaHWskCed_MIid3KpJH5Lbatf9HsdXBAZH5YcvPAbMhJUKzTJyzgvXZYpBS');

// File location on server
$file_path = '/absolute/path/to/file/on/server.ext';

// Create File object
$file = (object) [
    'tmp_path' => $file_path,
    'type' => mime_content_type($file_path),
    'name' => 'filename.ext',
    'size' => filesize($file_path),
];

$entry = WPCP_ONEDRIVE_API::upload_file($file, '01EXLSWHRCD7RDL3HX65BK5X3ULXLWSICN', 'A simple description', false);
```

{% endtab %}

{% tab title="Google Drive" %}

### **Parameters**

<table><thead><tr><th width="232">Name</th><th width="93">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>$file</code></td><td>File object</td><td>Object containing the file details. Same as file object in <code>$_FILES</code>.</td></tr><tr><td><code>$upload_folder_id</code></td><td>string</td><td>ID of the upload folder.</td></tr><tr><td><code>$description</code></td><td>string</td><td>Description for the file.</td></tr><tr><td><code>$overwrite</code></td><td>bool</td><td>Overwrite an existing file with the same name? If false, the file will be renamed.</td></tr></tbody></table>

### **Return**

<table><thead><tr><th width="184">Name</th><th width="167">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>$node</code></td><td><strong>CachedNode</strong></td><td>The object for the uploaded file.</td></tr></tbody></table>

### **Usage**

```php
WPCP_GDRIVE_API::set_account_by_id('201096615285735764133')

// File location on server
$file_path = '/absolute/path/to/file/on/server.ext';

// Create File object
$file = (object) [
    'tmp_path' => $file_path,
    'type' => mime_content_type($file_path),
    'name' => 'filename.ext',
    'size' => filesize($file_path),
];

$entry = WPCP_GDRIVE_API::upload_file($file, '1FCYkOJb150I8nl8DE92YIXWaB0J7VOk5', 'A simple description', false);
```

{% endtab %}

{% tab title="Dropbox" %}

### **Parameters**

<table><thead><tr><th width="232">Name</th><th width="93">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>$file</code></td><td>File object</td><td>Object containing the file details. Same as file object in <code>$_FILES</code>.</td></tr><tr><td><code>$dropbox_path</code></td><td>string</td><td>The upload PATH on Dropbox containing the filename /path/to/folder/filename.ext</td></tr></tbody></table>

### **Return**

<table><thead><tr><th width="184">Name</th><th width="167">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>$entry</code></td><td><strong>Entry</strong></td><td>The object for the uploaded file.</td></tr></tbody></table>

### **Usage**

```php
WPCP_DROPBOX_API::set_account_by_id('dbid:AADSy6JxzbgqCs4A43CAAAfO9xvZwpcsLU');

// File location on server
$file_path = '/absolute/path/to/file/on/server.ext';

// Create File object
$file = (object) [
    'tmp_path' => $file_path,
    'type' => mime_content_type($file_path),
    'name' => 'filename.ext',
    'size' => filesize($file_path),
];

$entry = WPCP_DROPBOX_API::upload_file($file, '/Documents/filename.ext')
```

{% endtab %}

{% tab title="Box" %}

### **Parameters**

<table><thead><tr><th width="232">Name</th><th width="93">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>$file</code></td><td>File object</td><td>Object containing the file details. Same as file object in <code>$_FILES</code>.</td></tr><tr><td><code>$upload_folder_id</code></td><td>string</td><td>ID of the upload folder.</td></tr><tr><td><code>$description</code></td><td>string</td><td>Description for the file.</td></tr><tr><td><code>$overwrite</code></td><td>bool</td><td>Overwrite an existing file with the same name? If false, the file will be renamed.</td></tr></tbody></table>

### **Return**

<table><thead><tr><th width="210">Name</th><th width="146">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>$node</code></td><td><strong>CachedNode</strong></td><td>The object for the uploaded file.</td></tr></tbody></table>

### **Usage**

```php
WPCP_BOX_API::set_account_by_id('29232154182');

// File location on server
$file_path = '/absolute/path/to/file/on/server.ext';

// Create File object
$file = (object) [
    'tmp_path' => $file_path,
    'type' => mime_content_type($file_path),
    'name' => 'filename.ext',
    'size' => filesize($file_path),
];

$entry = WPCP_BOX_API::upload_file($file, '511426724354', 'A simple description', false);
```

{% endtab %}
{% endtabs %}
