UploadFile

Overview

The UploadFile class handles the various tasks when uploading a file.

Retrieving a Files Upload Location

To retrieve a files upload path, you can use the get_upload_path method and pass in the files GUID id.
require_once('include/upload_file.php');

UploadFile::get_upload_path($file_id);
This method will normally return the path as:
upload://1d0fd9cc-02e5-f6cd-1426-51a509a63334

Retrieving a Files Full File System Location

To retrieve a files full system path path, you can use the get_upload_path and real_path methods as shown below:
require_once('include/upload_file.php');

UploadFile::realpath(UploadFile::get_upload_path($file_id));
This method will normally return the path as:
/Library/WebServer/htdocs/sugarcrm/upload/1d0fd9cc-02e5-f6cd-1426-51a509a63334

Retrieving a Files Contents

Alternative to using file_get_contents or sugar_file_get_contents, you can retrieve the contents of a file using the get_file_contents method as shown below:
require_once('include/upload_file.php');



$file = new UploadFile();



//get the file location

$file->temp_file_location = UploadFile::get_upload_path($file_id);

$file_contents = $file->get_file_contents();