Trying to develop a webForm with html-php-curl


#1

Hey there,

I'm trying to develop a webform to allow me and my users 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

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

I don't know if I have to declare something extra in my code:

<form  action="cr.php" method="post" enctype="multipart/form-data">
    <input type="file" name="upload" />
    <input type="submit" value="Upload the file">
</form>

<?php

if ($_FILES['upload']['tmp_name']){
    
    // for debugin purposes echo $_FILES['upload']['tmp_name'] ;
    $ch = curl_init();
    $cfile = new CURLFile ($_FILES['upload']['tmp_name'],$_FILES['upload']['type'],$_FILES['upload']['name']);
    $data = array ("upload"=>$cfile);
    
    curl_setopt($ch,CURLOPT_URL, "http://domain.com/owncloud/remote.php/webdav/");
    curl_setopt($ch,CURLOPT_HTTPHEADER,'Authorization: Basic');
    curl_setopt($ch,CURLOPT_USERPWD, "user:password");
    curl_setopt($ch,CURLOPT_PUT, 1);
    curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
    
    
    $subida = curl_exec($ch);
        
        if($subida == true){
                echo "<br>";
                echo "The file was uploaded <br>";
                echo "File data:<br>".$_FILES['upload']['tmp_name']."<br>".$_FILES['upload']['type']."<br>".$_FILES['upload']['name'];
            
        }else{

            echo "Error: " . curl_error($ch);
        }

    }


?>

I was trying to use PUT to upload files too but the method wasn't supported by ownCloud.

Please help me to solve this.
Regards


Necesito hacer un formulario web para subir archivos
#2

Hi,

you might find a lot of infos what you're doing wrong (using PUT to remote.php/webdav/ instead of remote.php/webdav/filename.jpg) at this thread:


#3

I've already checked the post but I'm a bit confused, I'm new to this type of scripting and the code posted on your reference seems to a comand line upload through curl, so can you guide me a bit to how to port that code to php? because my objective is make a html form to be published on web.

Thanks for your answer.
Regards


Necesito hacer un formulario web para subir archivos
#4

Hi,

for porting such stuff to PHP its probably better to ask on a forums dedicated to PHP programming.