Open Journal Systems  3.3.0
FileManager Class Reference
Inheritance diagram for FileManager:
IssueFileManager PKPPublicFileManager PrivateFileManager PublicFileManager ContextFileManager PKPLibraryFileManager TemporaryFileManager BaseSubmissionFileManager LibraryFileManager SubmissionFileManager

Public Member Functions

 __construct ()
 
 compressFile ($filePath)
 
 copyDir ($source, $dest)
 
 copyFile ($source, $dest)
 
 decompressFile ($filePath)
 
 deleteByPath ($filePath)
 
 downloadByPath ($filePath, $mediaType=null, $inline=false, $fileName=null)
 
 fileExists ($filePath, $type='file')
 
 getDocumentExtension ($type)
 
 getDocumentType ($type)
 
 getExtension ($fileName)
 
 getFirstUploadedPostName ()
 
 getImageExtension ($type)
 
 getNiceFileSize ($size)
 
 getUploadedFileName ($fileName)
 
 getUploadedFilePath ($fileName)
 
 getUploadedFileType ($fileName)
 
 getUploadErrorCode ($fileName)
 
 mkdir ($dirPath, $perms=null)
 
 mkdirtree ($dirPath, $perms=null)
 
 parseFileExtension ($fileName)
 
 readFileFromPath ($filePath, $output=false)
 
 rmdir ($dirPath)
 
 rmtree ($file)
 
 setMode ($path, $mask)
 
 truncateFileName ($fileName, $length=127)
 
 uploadedFileExists ($fileName)
 
 uploadError ($fileName)
 
 uploadFile ($fileName, $destFileName)
 
 writeFile ($dest, &$contents)
 

Detailed Description

Class defining basic operations for file management.

Definition at line 35 of file FileManager.inc.php.

Constructor & Destructor Documentation

◆ __construct()

FileManager::__construct ( )

Constructor

Reimplemented in PrivateFileManager, and TemporaryFileManager.

Definition at line 39 of file FileManager.inc.php.

Member Function Documentation

◆ compressFile()

FileManager::compressFile (   $filePath)

Compress passed file.

Parameters
$filePathstring The file to be compressed.
Returns
string The file path that was created.

Definition at line 581 of file FileManager.inc.php.

◆ copyDir()

FileManager::copyDir (   $source,
  $dest 
)

Copy a directory. Adapted from code by gimmicklessgpt at gmail dot com, at http://php.net/manual/en/function.copy.php

Parameters
$sourcestring the path to the source directory
$deststring the path where the directory is to be saved
Returns
boolean returns true if successful

Definition at line 192 of file FileManager.inc.php.

References copyFile(), fileExists(), and mkdir().

◆ copyFile()

FileManager::copyFile (   $source,
  $dest 
)

Copy a file.

Parameters
$sourcestring the source URL for the file
$deststring the path where the file is to be saved
Returns
boolean returns true if successful

Definition at line 174 of file FileManager.inc.php.

References fileExists(), mkdirtree(), and setMode().

Referenced by PKPPublicFileManager\copyContextFile(), copyDir(), PKPLibraryFileManager\copyFromTemporaryFile(), and IssueFileManager\fromTemporaryFile().

◆ decompressFile()

FileManager::decompressFile (   $filePath)

Decompress passed gziped file.

Parameters
$filePathstring
Returns
string The file path that was created.

Definition at line 572 of file FileManager.inc.php.

◆ deleteByPath()

FileManager::deleteByPath (   $filePath)

Delete a file.

Parameters
$filePathstring the location of the file to be deleted
Returns
boolean returns true if successful

Definition at line 291 of file FileManager.inc.php.

References HookRegistry\call(), and fileExists().

Referenced by PKPPublicFileManager\removeContextFile(), and PKPPublicFileManager\removeSiteFile().

◆ downloadByPath()

FileManager::downloadByPath (   $filePath,
  $mediaType = null,
  $inline = false,
  $fileName = null 
)

Download a file. Outputs HTTP headers and file content for download

Parameters
$filePathstring the location of the file to be sent
$mediaTypestring the MIME type of the file, optional
$inlineboolean print file as inline instead of attachment, optional
$fileNamestring Optional filename to use on the client side
Returns
boolean

Definition at line 256 of file FileManager.inc.php.

References HookRegistry\call(), PKPString\mime_content_type(), and readFileFromPath().

◆ fileExists()

FileManager::fileExists (   $filePath,
  $type = 'file' 
)

Check if a file path is valid;

Parameters
$filePathstring the file/directory to check
$typestring (file|dir) the type of path

Definition at line 375 of file FileManager.inc.php.

Referenced by SubmissionFileManager\_handleCopy(), copyDir(), copyFile(), deleteByPath(), TemporaryFileManager\handleUpload(), TemporaryFileManager\submissionToTemporaryFile(), uploadFile(), and writeFile().

◆ getDocumentExtension()

FileManager::getDocumentExtension (   $type)

Returns file extension associated with the given document type, or false if the type does not belong to a recognized document type.

Parameters
$typestring

Definition at line 428 of file FileManager.inc.php.

◆ getDocumentType()

FileManager::getDocumentType (   $type)

Returns a file type, based on generic categories defined above

Parameters
$typeString
Returns
string (Enuemrated DOCUMENT_TYPEs)

Definition at line 391 of file FileManager.inc.php.

References getImageExtension().

◆ getExtension()

FileManager::getExtension (   $fileName)

Parse file extension from file name.

Parameters
stringa valid file name
Returns
string extension

Definition at line 498 of file FileManager.inc.php.

Referenced by PKPLibraryFileManager\generateFileName(), and truncateFileName().

◆ getFirstUploadedPostName()

FileManager::getFirstUploadedPostName ( )

Get the filename of the first uploaded file in the $_FILES array. The returned filename is the value used in the form that submitted the request.

Returns
string

Definition at line 79 of file FileManager.inc.php.

◆ getImageExtension()

FileManager::getImageExtension (   $type)

Returns file extension associated with the given image type, or false if the type does not belong to a recognized image type.

Parameters
$typestring

Definition at line 450 of file FileManager.inc.php.

Referenced by getDocumentType().

◆ getNiceFileSize()

FileManager::getNiceFileSize (   $size)

Return pretty file size string (in B, KB, MB, or GB units).

Parameters
$sizeint file size in bytes
Returns
string

Definition at line 522 of file FileManager.inc.php.

◆ getUploadedFileName()

FileManager::getUploadedFileName (   $fileName)

Return the user-specific (not temporary) filename of an uploaded file.

Parameters
$fileNamestring the name of the file used in the POST form
Returns
string (boolean false if no such file)

Definition at line 100 of file FileManager.inc.php.

Referenced by SubmissionFileManager\_handleUpload(), and TemporaryFileManager\handleUpload().

◆ getUploadedFilePath()

FileManager::getUploadedFilePath (   $fileName)

Return the (temporary) path to an uploaded file.

Parameters
$fileNamestring the name of the file used in the POST form
Returns
string (boolean false if no such file)

Definition at line 88 of file FileManager.inc.php.

Referenced by SubmissionFileManager\_handleUpload().

◆ getUploadedFileType()

FileManager::getUploadedFileType (   $fileName)

Return the type of an uploaded file.

Parameters
$fileNamestring the name of the file used in the POST form
Returns
string

Definition at line 112 of file FileManager.inc.php.

References PKPString\mime_content_type().

Referenced by SubmissionFileManager\_handleUpload().

◆ getUploadErrorCode()

FileManager::getUploadErrorCode (   $fileName)

Get the error code of a file upload

See also
http://php.net/manual/en/features.file-upload.errors.php
Parameters
$fileNamestring the name of the file used in the POST form
Returns
integer

Definition at line 70 of file FileManager.inc.php.

◆ mkdir()

FileManager::mkdir (   $dirPath,
  $perms = null 
)

Create a new directory.

Parameters
$dirPathstring the full path of the directory to be created
$permsstring the permissions level of the directory (optional)
Returns
boolean returns true if successful

Definition at line 306 of file FileManager.inc.php.

References setMode().

Referenced by copyDir(), and mkdirtree().

◆ mkdirtree()

FileManager::mkdirtree (   $dirPath,
  $perms = null 
)

Create a new directory, including all intermediate directories if required (equivalent to "mkdir -p")

Parameters
$dirPathstring the full path of the directory to be created
$permsstring the permissions level of the directory (optional)
Returns
boolean returns true if successful

Definition at line 355 of file FileManager.inc.php.

References fatalError(), and mkdir().

Referenced by copyFile(), TemporaryFileManager\handleUpload(), TemporaryFileManager\submissionToTemporaryFile(), uploadFile(), and writeFile().

◆ parseFileExtension()

FileManager::parseFileExtension (   $fileName)

Parse the file extension from a filename/path.

Parameters
$fileNamestring
Returns
string

Definition at line 548 of file FileManager.inc.php.

Referenced by IssueFileManager\fromTemporaryFile(), TemporaryFileManager\handleUpload(), and TemporaryFileManager\submissionToTemporaryFile().

◆ readFileFromPath()

FileManager::readFileFromPath (   $filePath,
  $output = false 
)

Read a file's contents.

Parameters
$filePathstring the location of the file to be read
$outputboolean output the file's contents instead of returning a string
Returns
string|boolean

Definition at line 227 of file FileManager.inc.php.

Referenced by downloadByPath().

◆ rmdir()

FileManager::rmdir (   $dirPath)

Remove a directory.

Parameters
$dirPathstring the full path of the directory to be delete
Returns
boolean returns true if successful

Definition at line 321 of file FileManager.inc.php.

Referenced by rmtree().

◆ rmtree()

FileManager::rmtree (   $file)

Delete all contents including directory (equivalent to "rm -r")

Parameters
$filestring the full path of the directory to be removed
Returns
boolean true iff success, otherwise false

Definition at line 330 of file FileManager.inc.php.

References rmdir().

◆ setMode()

FileManager::setMode (   $path,
  $mask 
)

Set file/directory mode based on the 'umask' config setting.

Parameters
$pathstring
$maskint
Returns
boolean

Definition at line 536 of file FileManager.inc.php.

References Config\getVar().

Referenced by copyFile(), mkdir(), uploadFile(), and writeFile().

◆ truncateFileName()

FileManager::truncateFileName (   $fileName,
  $length = 127 
)

◆ uploadedFileExists()

FileManager::uploadedFileExists (   $fileName)

Return true if an uploaded file exists.

Parameters
$fileNamestring the name of the file used in the POST form
Returns
boolean

Definition at line 47 of file FileManager.inc.php.

Referenced by SubmissionFileManager\_handleUpload().

◆ uploadError()

FileManager::uploadError (   $fileName)

Return true iff an error occurred when trying to upload a file.

Parameters
$fileNamestring the name of the file used in the POST form
Returns
boolean

Definition at line 60 of file FileManager.inc.php.

◆ uploadFile()

FileManager::uploadFile (   $fileName,
  $destFileName 
)

Upload a file.

Parameters
$fileNamestring the name of the file used in the POST form
$deststring the path where the file is to be saved
Returns
boolean returns true if successful

Definition at line 134 of file FileManager.inc.php.

References fileExists(), mkdirtree(), and setMode().

Referenced by TemporaryFileManager\handleUpload(), PKPPublicFileManager\uploadContextFile(), and PKPPublicFileManager\uploadSiteFile().

◆ writeFile()

FileManager::writeFile (   $dest,
$contents 
)

Write a file.

Parameters
$deststring the path where the file is to be saved
$contentsstring the contents to write to the file
Returns
boolean returns true if successful

Definition at line 152 of file FileManager.inc.php.

References fileExists(), mkdirtree(), and setMode().

Referenced by PKPPublicFileManager\writeContextFile().


The documentation for this class was generated from the following file: