Uploading a file to ownCloud through PHP and a HTML Form

I'm having some troubles trying to develop a webapp for uploading files to my owncloud server trough a form using PHP, I'm using curl to PUT a request through the webDav, so here's the code:

Index.php

<html>
        <head>
            <title>Theform is here</title>
        </head>
        <body>
            <div align="center">
                <h1> File uploads with OwnCloud API</h1>
                <form method="post" action="uploader.php" name="fileuploader">
                    <label>Select a File to upload</label><br>
                    <input type="file" name="file"></input><br>
                    <input type="submit" value="upload file"></input>
                </form>
                <?php
                ?>
            </div>
        </body>
    </html>

uploader.php

<?php
    $request = curl_init('http://mydomain.cl/owncloud/remote.php/webdav/Dev/');

    curl_setopt($request,CURLOPT_POST,true);
    curl_setopt($request,CURLOPT_HTTPHEADER,'Authorization: Basic');
    curl_setopt($request, CURLOPT_USERPWD, "user:password");
    curl_setopt($request, CURLOPT_PUT, 1);
    curl_setopt(
        $request,
        CURLOPT_INFILE,
        array(
            'thefile'=>
                        '@'            .$_FILES['file']['tmp_name']
                        . ';filename=' .$_FILES['file']['daName']
                        . ';type='     .$_FILES['file']['type']

        ));
    curl_setopt($request, CURLOPT_INFILE, $_FILES['file']);
    curl_setopt($request, CURLOPT_INFILESIZE, filesize($_FILES['file']));


    // output the response
    curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($request, CURLOPT_BINARYTRANSFER, TRUE); 
    echo curl_exec($request);

    // close the session
    curl_close($request);

?>

When I try to upload the file I get this response:

Sabre\DAV\Exception\NotAuthenticated No 'Authorization: Basic' header found. Either the client didn't send one, or the server is mis-configured

But when I use the owncloud Client I can access to my files without problems.

EDIT: Corrected the name variable $ch to $request and added the line :

curl_setopt($request,CURLOPT_HTTPHEADER,'Authorization: Basic');

from @Craig post, after that I got this error message:

Sabre\DAV\Exception\Conflict PUT is not allowed on non-files.

Please help me to solve this. Regards :D


Include this in your curl options:

CURLOPT_HTTPHEADER => array('Authorization: Basic');

or to use your existing convention:

curl_setopt($ch, CURLOPT_HTTPHEADER, 'Authorization: Basic');

Trying to develop a webForm with html-php-curl - Server, to upload files to a specific folder through a html form using php and curl, but when I try to upload a file the server returns the message Sabr… Click on ‘All files’ (1) and then click on the folder you would like to add a file to (2). Click on the upload icon (3). 2. This will open the browsing window.


Finally to manage my files through owncloud I had to point the form to a directorory on the webserver and then used the owncloud plugin to mount external storage sources and works pretty fine to me.

External Storage Configuration

Use CURL to upload files to OC - Server, Trying to develop a webForm with html-php-curl. Syncing new files from ownCloud Server to Windows Desktop Client. anon30676603 September 19, 2016,  The file/folder needs to exist in the ownCloud database. Moving a file/folder into ownCloud's data directory doesn't add it to the database automatically. Luckily, the ownCloud developers were kind enough to create a command line tool called occ that can manually add missing files and folders to the ownCloud database. You can run the following


To upload file to owncloud with html form and php

<html>
        <head>
            <title>Theform is here</title>
        </head>
        <body>
            <div align="center">
                <h1> File uploads with OwnCloud API</h1>
                <form method="post" action="" name="fileuploader" enctype="multipart/form-data">
                    <label>Select a File to upload</label><br>
                    <input type="file" name="file"></input><br>
                    <input type="submit" name="submit" value="upload file"></input>
                </form>
                <?php
                ?>
            </div>
        </body>
    </html>


$file_path_str = $_FILES['file']['tmp_name'];
$filename=$_FILES['file']['name'];
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://server/owncloud/remote.php/webdav/' . basename($filename));
curl_setopt($ch, CURLOPT_FAILONERROR, true); 
curl_setopt($ch, CURLOPT_USERPWD, "user:password");
curl_setopt($ch, CURLOPT_PUT, 1);

$fh_res = fopen($file_path_str, 'r');

curl_setopt($ch, CURLOPT_INFILE, $fh_res);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file_path_str));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary

$curl_response_res = curl_exec ($ch);
if (curl_errno($ch)) {
    $error_msg = curl_error($ch);
    print_r($error_msg);exit;
}
fclose($fh_res);

Uploading big files > 512MB, The default maximum file size for uploads is 512MB. Because php-fpm can't read PHP settings in .htaccess these settings must be set in the an admin can change the upload limits on demand by using the File handling input box within the  There are many scripts available on the web to assist with uploading files to a server using a web browser. However, it isn't difficult to create a simple user interface that allows someone to upload files using a simple HTML form and PHP script. In this example, I am going to use an HTML form, and it will submit to the same page. Lets start


Big File Upload Configuration :: ownCloud Documentation, ownCloud comes with its own owncloud/.htaccess file. Because php-fpm can't read PHP settings in .htaccess these settings must  The index.php file holds code which is responsible for displaying the file upload form. On the other hand, the upload.php file is responsible for uploading a file to the server. Also, a file will be uploaded in the uploaded_files directory, so you need to make sure that this folder exists and is writable by the web-server user.


Config.php Parameters :: ownCloud Documentation, ownCloud supports loading configuration parameters from multiple files. You can add arbitrary files ending with .config.php in the config/ directory, before a search returns results for users or groups in the share autocomplete form. /​server/latestadmin_manual/configuration/files/file_versioning.html for more information. Without the requirements above, the file upload will not work. Other things to notice: The type="file" attribute of the <input> tag shows the input field as a file-select control, with a "Browse" button next to the input control ; The form above sends data to a file called "upload.php", which we will create next.


var/www/owncloud/apps/files/ajax/upload.php · mdupain , <?php /** * @author Arthur Schiwon <blizzz@owncloud.com> * @author Bart in the HTML form'), UPLOAD_ERR_PARTIAL => $l->t('The uploaded file was  Open a new HTML document from any code editor. 2. Create a HTML form with a text files to enter the uploading folder’s name, file field to upload the folder and a submit button to complete the upload task. Add the following HTML code create the form.