Member variable HttpUploadedFile():IsOnDisk Foundation

Specifies whether the file is stored on disk.

Attribute: EXPORTED
Data type: Logical (.F.)
Description

The member variable :IsOnDisk specifies whether the file was saved to the web server’s hard disk during the upload process or if it only exists in memory. If :IsOnDisk is .T. (true), the file is disk-based. ln this case, the :NameOnDisk member variable contains the full pathname of the file. If .F. is assigned to:IsOnDisk, the file only exists in memory.

For further details on how to configure uploaded file management, please refer to Global in this documentation.

Example:

The following example demonstrates an efficient way to receive files where it is not feasible to hold the file content in memory. Receiving files where the file size is expected to be more then several Megabyte or Gigabyte is an example for such a case.

Assume the configuration file global.config contains the following XML fragment, which configures <CXP/> to store uploaded files on the web server’s harddisk:

<HttpManager 
   UseUploadFolder="yes" 
/> 

The following code is an excerpt from the <CXP/> page which processes the uploaded file. Because the file is known to reside on disk, the code just associates the file’s pathname with a unique id for later retrieval. In this example, this is the id of the customer (CID) currently selected, which is read from session variable. This approach prevents the file from being loaded into memory, which is what would have occurred if the file was accessed via the member variable :Data. Instead, dedicated code can be written for processing the file at a later stage, if needed. Successively reading in chunks of data using the file functions makes it unnecessary to keep the whole file in memory, for insstance.

< % 
IF 0 != ::HttpRequest:Files:NumItems 
   oHttpUploadedFile := ::HttpRequest:Files:filedata 
   IF oHttpUploadedFile:IsOnDisk 
      ? "<h1>File has been received</h1>" 
      FILESTORE->PATHNAME := oHttpUploadedFile:NameOnDisk 
      FILESTORE->CUST_ID  := ::Session:CustomerId 
   ELSE 
      ? "<h1>Error</h1>" 
      ? "<p>" 
      ? "System configuration is incorrect: files need to be stored on disk!" 
      ? "</p>" 
   ENDIF 
ENDIF 
%> 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.