/** * function initialize image file by link * * @param string $fileLink full path to file (ex.'/var/www/test.png') * @param string $fileUserName user file name * @param string $fileTitle file title * @param string $fileMime file mime type * * @return bool is file set * */ function initialize($fileLink, $fileUserName = null, $fileTitle = null, $fileMime = null) { if (parent::initialize($fileLink, $fileUserName, $fileTitle, $fileMime)) { $this->refreshImageSize(); return true; } else { return false; } }
<?php /* * Set up the file archive environment. */ $GLOBALS['pie']['log'] = 'File Archive'; if (!file_exists("{$lib}/class/file.php")) { bye("The file class library could not be found."); } include_once "{$lib}/class/file.php"; $file = new File(); if (!$file->initialize()) { bye("The file database could not be initialized."); }
<?php if (!empty($attributes['id'])) { if (is_numeric($attributes['id'])) { $arrAttachment = $ogArticleAttachmentManager->getAttachment($attributes['id']); $ogArticleAttachmentManager->removeAttachment($attributes['id']); $oFile = new File(); if ($oFile->initialize($fusebox['pathArticleAttachment'] . $arrAttachment['file'])) { $oFileManager->deleteFile($oFile); } } else { _error("EInvalidAttachmentId", "Invalid attachment ID"); } } else { _error("ENoAttachmentGiven", "No attachment is given to delete"); }
/** * function upload file to server * * @param string $uploadFile 'file' field name at form * @param string $uploadDir dir where upload file * * @return File file object uploaded on server */ function uploadFile($uploadFile, $uploadDir, $fileName = null) { if (empty($uploadDir)) { $this->farrErrors[] = "File upload dir not set"; return false; } if (array_key_exists($uploadFile, $_FILES) && !is_array($_FILES[$uploadFile])) { $this->farrErrors[] = "File upload error. Please try again"; return false; } if (!@file_exists($_FILES[$uploadFile]['tmp_name'])) { $this->farrErrors[] = "File upload error. Please try again"; return false; } if ($uploadDir[strlen($uploadDir) - 1] != "/" || $uploadDir[strlen($uploadDir) - 1] != "\\") { $uploadDir .= "/"; } if (!empty($fileName)) { $destFilePath = $uploadDir . $fileName; } else { $destFilePath = $uploadDir . basename($_FILES[$uploadFile]['name']); } $counter = 1; $path = pathinfo($destFilePath); $dir = $path['dirname'] . "/"; $extension = '.' . $path['extension']; $name = basename($destFilePath, $extension); $mimeType = $_FILES[$uploadFile]['type']; /** not working on any random machine if (function_exists('mime_content_type')) { $mimeType = mime_content_type($_FILES[$uploadFile]['tmp_name']); } */ if (!empty($this->farrAllowedMimeTypes) && !array_key_exists($mimeType, array_flip($this->farrAllowedMimeTypes))) { $this->farrErrors[] = "File type not allowed"; return false; } while (@file_exists($destFilePath)) { $destFilePath = $dir . $name . '_' . $counter . $extension; $counter++; } if (@move_uploaded_file($_FILES[$uploadFile]['tmp_name'], $destFilePath)) { $oFile = new File(); if ($oFile->initialize($destFilePath, $name . $extension, $name, $mimeType)) { return $oFile; } else { $farrErrors[] = "File upload error"; return false; } } else { $farrErrors[] = 'File upload error'; return false; } }
<?php if (!empty($attributes['id'])) { if ($arrAttachment = $ogArticleAttachmentManager->getAttachment(intval($attributes['id']))) { $oFile = new File(); $oFile->initialize($fusebox['pathArticleAttachment'] . $arrAttachment['file'], null, $arrAttachment['title'], $arrAttachment['mime']); $oFileManager->downloadFile($oFile); } }