EnglishDeutschFrançais

1.15 How can I implement a file upload mechanism without using WebDAV?

In order to upload files without using WebDAV you can work with HTTP connections. To do so, you have to activate the HTTP POST mechanism within the configuration file and specify a server-side script.

The first step is to activate the HTTP POST upload mechanism for images, multimedia objects and documents in the "config.xml" file, e.g.:

 

...

<filemanagement>

      <file type="image" baseurl="http://www.myserver.com/"

       autoupload="true"

       onuploadfinished="uploadStatusReport">

       <http url="http://www.myserver.com/upload.php" />

      </file>

      <file type="object" baseurl="http://www.myserver.com/"

       autoupload="true">

       <http url="http://www.myserver.com/upload.php" />

      </file>

      <file type="document" baseurl="http://www.myserver.com/" >

       <http url="http://www.myserver.com/upload.php" />

      </file>

 </filemanagement>

...

 

Then you have to specify a server-side script which manages the file upload. By uploading files using the HTTP POST upload mechanism (see above), every file will be kept in a form field called "uploadfile". To make sure that the file was uploaded successfully, the server-side script must return "OK" resp. "Failed" if not.
Below please find a sample for the image upload:

 

...

 <?php

 $filename = $_FILES["uploadfile"]["name"];

 $tmp_name = $_FILES["uploadfile"]["tmp_name"];

 

 if(file_exists($filename)) {

       while(file_exists($filename)) {

          $ext = strchr($filename,".");

          $pos = strpos($filename,".");

        $filename = substr($filename,0,$pos)."$".$ext;

       }

 }

 

 if($fp = fopen($tmp_name,"rb")) {

       $file = fread ($fp, filesize($tmp_name));

       fclose($fp);

 } else

       die("Failed");

 

 if($fp = fopen($filename,"wb")) {

       fwrite($fp,$file);

       fclose($fp);

 } else

       die("Failed");

 

 echo "OK";

 echo "|http://yourserver.com/eop4".$filename."|";

 ?>

...

 

For more information please review the edit-on Pro Integration Manual, chapter "2.9. Managing embedded files".

 

Copyright © 2000-2008 RealObjects GmbH