本文整理汇总了PHP中JFile::upload方法的典型用法代码示例。如果您正苦于以下问题:PHP JFile::upload方法的具体用法?PHP JFile::upload怎么用?PHP JFile::upload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JFile
的用法示例。
在下文中一共展示了JFile::upload方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getData
public function getData()
{
ob_clean();
$app = JFactory::getApplication();
$session = JFactory::getSession();
$post = JRequest::get('post');
$files = JRequest::get('files');
$files = $files[$post['task'] . $post['import']];
if (isset($post['task']) && isset($post['import'])) {
if ($files['name'] == "") {
return JText::_('PLEASE_SELECT_FILE');
}
$ext = strtolower(JFile::getExt($files['name']));
if ($ext != 'csv') {
return JText::_('FILE_EXTENSION_WRONG');
}
} else {
if (!isset($post['import'])) {
return JText::_('PLEASE_SELECT_SECTION');
}
}
// Upload csv file
$src = $files['tmp_name'];
$dest = JPATH_ROOT . '/components/com_redshop/assets/importcsv/' . $post['import'] . '/' . $files['name'];
$file_upload = JFile::upload($src, $dest);
$session->clear('ImportPost');
$session->clear('Importfile');
$session->clear('Importfilename');
$session->set('ImportPost', $post);
$session->set('Importfile', $files);
$session->set('Importfilename', $files['name']);
$app->Redirect('index.php?option=com_redshop&view=import&layout=importlog');
return;
}
示例2: upload
function upload($file)
{
$uploadPath = JPATH_ROOT . DS . 'images' . DS . 'phocagallery' . DS . 'tabla' . DS . $file['name'];
if (!JFile::upload($file['tmp_name'], $uploadPath)) {
return False;
}
}
示例3: subir
public function subir()
{
$jinput = JFactory::getApplication()->input;
/**
* Esta tarea debe accionarse sólamente cuándo el artículo ha sido previamente guardado,
* con el fin de evitar subir archivos huerfanos
*/
$id = $jinput->get->get('id', null, null);
if ($id == 0) {
print_r('Debe haber guardado el artículo para agregar adjuntos');
return;
}
// Obtiene la variable @campo enviada en el request
$campo = $jinput->get->get('campo', null, null);
$archivo = $jinput->files->get($campo);
if (isset($archivo)) {
// Sanea el nombre de archivo evitando caracteres no deseados
$nombreArchivo = strtolower(JFile::makeSafe($archivo['name']));
// Define el origen y destino del archivo
// TODO: Crear directorio propio para los adjuntos del artículo
// y usarlo como path destino.
$src = $archivo['tmp_name'];
$dest = JPATH_ROOT . DS . 'uploads' . DS . sha1(time()) . '-' . $nombreArchivo;
if (JFile::upload($src, $dest)) {
// TODO: Implementa/valida una estructura de datos para los nombres
// de los archivos que se guardan en la base de datos
print_r("Archivo Subido");
} else {
print_r("Ha ocurrido un error");
print_r($archivo['error']);
}
}
}
示例4: upload
function upload($file, $path, $override = 0)
{
//Import filesystem libraries. Perhaps not necessary, but does not hurt
jimport('joomla.filesystem.file');
//Clean up filename to get rid of strange characters like spaces etc
$filename = JFile::makeSafe($file['name']);
$filename = str_replace(' ', '-', $filename);
//Set up the source and destination of the file
$src = $file['tmp_name'];
$dest = $path . $filename;
//First check if the file has the right extension, we need jpg only
$ext = strtolower(JFile::getExt($filename));
if ($ext == 'jpg' or $ext == 'gif' or $ext == 'png' or $ext == 'jpeg') {
//check exits
if (!$override) {
if (JFile::exists($dest)) {
echo "<script> alert('Image {$filename} exists on server');\r\n\t\t\t\t\t\twindow.history.go(-1); </script>\n";
exit;
}
}
if (JFile::upload($src, $dest)) {
return $filename;
} else {
echo "<script> alert('Error upload image');\r\n\t\t\twindow.history.go(-1); </script>\n";
exit;
}
} else {
echo "<script> alert('Chi cho phep cac loai anh: jpg, gif, png');\r\n\t\t\twindow.history.go(-1); </script>\n";
exit;
}
return false;
}
示例5: upload
/**
* Receives H5P upload requests from views/h5p/tmpl/upload.php
*/
public function upload()
{
$destination_folder = JFactory::getConfig()->get('tmp_path') . DIRECTORY_SEPARATOR . uniqid('h5ptmp-');
$destination_path = $destination_folder . DIRECTORY_SEPARATOR . $_FILES['h5p']['name'];
$tmp_name = $_FILES['h5p']['tmp_name'];
if (!$tmp_name || !JFile::upload($tmp_name, $destination_path, FALSE)) {
H5PJoomla::setErrorMessage('Not able to upload the given file.');
print "\n\t\t\t\t<p>Unable to upload file. Is the file larger than the allowed file transfer size of the server?</p>\n\t\t\t\t<p><a href=\"javascript:window.history.back();\">Try again.</a></p>\n\t\t\t";
return;
}
$_SESSION['h5p_upload'] = $destination_path;
$_SESSION['h5p_upload_folder'] = $destination_folder;
$h5p_validator = H5PJoomla::getInstance('validator');
$valid = $h5p_validator->isValidPackage();
if (!$valid) {
H5PJoomla::setErrorMessage('The uploaded file was not a valid h5p package');
print "\n\t\t\t\t<p>Uploaded file did not validate as a proper H5P. See errors above for further explanation.</p>\n\t\t\t\t<p><a href=\"javascript:window.history.back();\">Try again.</a></p>\n\t\t\t";
return;
}
$h5p_storage = H5PJoomla::getInstance('storage');
$uid = uniqid('h5p-', true);
// uniqid is not quite UUID, but good enough here.
$library_updated = $h5p_storage->savePackage($uid);
$title = isset($_REQUEST['new-h5p-title']) ? $_REQUEST['new-h5p-title'] : "Untitled H5P upload";
// Response HTML
$document = JFactory::getDocument();
$document->setMimeEncoding('text/html');
print "\n\t\t\t<script type=\"text/javascript\">\n\t\t\t\twindow.parent.insertH5P('{$uid}', '{$title}');\n\t\t\t</script>\n\t\t";
}
示例6: getPackageFromUpload
function getPackageFromUpload()
{
$install_file = JRequest::getVar('package', null, 'files', 'array');
if (!(bool) ini_get('file_uploads')) {
$msg = 'File upload function is disabled, please enable it in file "php.ini"';
JError::raiseWarning('SOME_ERROR_CODE', JText::_($msg));
return false;
}
if (!extension_loaded('zlib')) {
$msg = 'Zlib library is disabled, please enable it in file "php.ini"';
JError::raiseWarning('SOME_ERROR_CODE', JText::_($msg));
return false;
}
if ($install_file['name'] == '') {
$msg = 'The package is not selected, please download and select it';
JError::raiseWarning('SOME_ERROR_CODE', JText::_($msg));
return false;
}
if (JFile::getExt($install_file['name']) != 'zip') {
$msg = 'The package has incorrect format, please use exactly the file you downloaded';
JError::raiseWarning('SOME_ERROR_CODE', JText::_($msg));
return false;
}
$tmp_dest = JPATH_ROOT . DS . 'tmp' . DS . $install_file['name'];
$tmp_src = $install_file['tmp_name'];
if (!JFile::upload($tmp_src, $tmp_dest)) {
$msg = 'Folder "tmp" is Unwritable, please set it to Writable (chmod 777). You can set the folder back to Unwritable after sample data installation';
JError::raiseWarning('SOME_ERROR_CODE', JText::_($msg));
return false;
}
$package = JInstallerHelper::unpack($tmp_dest);
return $package;
}
示例7: upload
/**
* Upload files and attach them to an issue or a comment.
*
* @param array $files Array containing the uploaded files.
* @param int $issueId ID of the issue/comment where to attach the files.
* @param int $commentId One of 'issue' or 'comment', indicating if the files should be attached to an issue or a comment.
*
* @return boolean True on success, false otherwise.
*/
public function upload($files, $issueId, $commentId = null)
{
if (!$issueId || !is_array($files)) {
return false;
}
jimport('joomla.filesystem.file');
if ($commentId) {
$type = 'comment';
$id = $commentId;
} else {
$type = 'issue';
$id = $issueId;
}
foreach ($files as $file) {
$rand = MonitorHelper::genRandHash();
$pathParts = array($type, $id, $rand . '-' . $file[0]['name']);
$path = JPath::clean(implode(DIRECTORY_SEPARATOR, $pathParts));
$values = array('issue_id' => $issueId, 'comment_id' => $commentId, 'path' => $path, 'name' => $file[0]['name']);
if (!JFile::upload($file[0]['tmp_name'], $this->pathPrefix . $path)) {
JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_MONITOR_ATTACHMENT_UPLOAD_FAILED', $file[0]['name']));
return false;
}
$query = $this->db->getQuery(true);
$query->insert('#__monitor_attachments')->set(MonitorHelper::sqlValues($values, $query));
$this->db->setQuery($query);
if ($this->db->execute() === false) {
return false;
}
}
return true;
}
示例8: checkUpload
/**
* checks uploaded file, and uploads it
* @return true csv file uploaded ok, false error (JErrir warning raised)
*/
function checkUpload()
{
if (!(bool)ini_get('file_uploads')) {
JError::raiseWarning(500, JText::_("The installer can't continue before file uploads are enabled. Please use the install from directory method."));
return false;
}
$userfile = JRequest::getVar('jform', null, 'files');
if (!$userfile) {
JError::raiseWarning(500, JText::_('COM_FABRIK_IMPORT_CSV_NO_FILE_SELECTED'));
return false;
}
jimport('joomla.filesystem.file');
$to = JPath::clean(COM_FABRIK_BASE.'media'.DS.$userfile['name']['userfile']);
$resultdir = JFile::upload($userfile['tmp_name']['userfile'], $to);
if ($resultdir == false) {
JError::raiseWarning(500, JText::_('Upload Error'));
return false;
}
$allowed = array('txt', 'csv', 'tsv');
if (!in_array(JFile::getExt($userfile['name']['userfile']), $allowed)) {
JError::raiseError(500, 'File must be a csv file');
return false;
}
return true;
}
示例9: installApplicationFromUserfile
/**
* Installs an Application from a user upload.
*
* @param array $userfile The userfile to install from
* @return int 2 = update, 1 = install
*
* @throws InstallHelperException
* @since 2.0
*/
public function installApplicationFromUserfile($userfile)
{
// Make sure that file uploads are enabled in php
if (!(bool) ini_get('file_uploads')) {
throw new InstallHelperException('Fileuploads are not enabled in php.');
}
// If there is no uploaded file, we have a problem...
if (!is_array($userfile)) {
throw new InstallHelperException('No file selected.');
}
// Check if there was a problem uploading the file.
if ($userfile['error'] || $userfile['size'] < 1) {
throw new InstallHelperException('Upload error occured.');
}
// Temporary folder to extract the archive into
$tmp_directory = $this->app->path->path('tmp:') . '/';
$archivename = $tmp_directory . $userfile['name'];
if (!JFile::upload($userfile['tmp_name'], $archivename)) {
throw new InstallHelperException("Could not move uploaded file to ({$archivename})");
}
// Clean the paths to use for archive extraction
$extractdir = $tmp_directory . uniqid('install_');
jimport('joomla.filesystem.archive');
// do the unpacking of the archive
if (!JArchive::extract($archivename, $extractdir)) {
throw new InstallHelperException("Could not extract zip file to ({$tmp_directory})");
}
return $this->installApplicationFromFolder($extractdir);
}
示例10: saveCategoryData
public function saveCategoryData($post)
{
//print_r($post); die;
$db = JFactory::getDbo();
$creationDate = date('Y-m-d H:i:s');
$query = $db->getQuery(true);
$allawExtation = array('jpg', 'jpeg', 'png', 'gif');
# These extantion allowed for upload logo file
$file = JRequest::getVar('categoryLogo', null, 'files', 'array');
$filename = JFile::makeSafe($file['name']);
$filextantion = strtolower(JFile::getExt($filename));
$fileScr = $file['tmp_name'];
$error = $this->validate($post, $filename, $filextantion, $allawExtation, $fileScr);
if (count($error) == 0) {
// Logo update start there
if ($filename != '') {
$tempFname = time() . '.' . $filextantion;
$logoName = str_replace(' ', '', $post['categoryName']) . '_' . $tempFname;
# File name to store into database
$src = $fileScr;
$dest = JPATH_BASE . "/images/productLogo/" . $logoName;
if (JFile::upload($src, $dest)) {
$conditional = $logoName;
}
}
$columns = array('categoryName', 'categoryImage', 'creationDate');
$values = array($db->quote($post['categoryName']), $db->quote($conditional), $db->quote($creationDate));
$query->insert($db->quoteName('onm_product_category'))->columns($db->quoteName($columns))->values(implode(',', $values));
$db->setQuery($query);
$result = $db->execute();
echo "<SCRIPT LANGUAGE='JavaScript'>\n window.alert('Category Added')\n window.location.href='index.php?option=com_membercheckin&view=addcategory';\n </SCRIPT>";
} else {
return $error;
}
}
示例11: upload
/**
* Upload a file
* @param string $source File to upload
* @param string $destination Upload to here
* @return True on success
*/
public static function upload($source, $destination)
{
$err = null;
$ret = false;
// Set FTP credentials, if given
jimport('joomla.client.helper');
JClientHelper::setCredentialsFromRequest('ftp');
// Load configurations.
$config = CFactory::getConfig();
// Make the filename safe
jimport('joomla.filesystem.file');
if (!isset($source['name'])) {
JError::raiseNotice(100, JText::_('COM_COMMUNITY_INVALID_FILE_REQUEST'));
return $ret;
}
$source['name'] = JFile::makeSafe($source['name']);
if (is_dir($destination)) {
jimport('joomla.filesystem.folder');
JFolder::create($destination, (int) octdec($config->get('folderpermissionsvideo')));
JFile::copy(JPATH_ROOT . '/components/com_community/index.html', $destination . '/index.html');
$destination = JPath::clean($destination . '/' . strtolower($source['name']));
}
if (JFile::exists($destination)) {
JError::raiseNotice(100, JText::_('COM_COMMUNITY_FILE_EXISTS'));
return $ret;
}
if (!JFile::upload($source['tmp_name'], $destination)) {
JError::raiseWarning(100, JText::_('COM_COMMUNITY_UNABLE_TO_UPLOAD_FILE'));
return $ret;
} else {
$ret = true;
return $ret;
}
}
示例12: upload
/**
* basic upload
* @return bool
*/
public function upload()
{
JRequest::checkToken() or die('Invalid Token');
$appl = JFactory::getApplication();
$file = JRequest::getVar('extension', '', 'files', 'array');
if ($file['tmp_name']) {
$path = $this->pathArchive;
// if the archive folder doesn't exist - create it!
if (!JFolder::exists($path)) {
JFolder::create($path);
} else {
// let us remove all previous uploads
$archiveFiles = JFolder::files($path);
foreach ($archiveFiles as $archive) {
if (!JFile::delete($this->pathArchive . '/' . $archive)) {
echo 'could not delete' . $archive;
}
}
}
$filepath = $path . '/' . strtolower($file['name']);
$object_file = new JObject($file);
$object_file->filepath = $filepath;
$file = (array) $object_file;
// let us try to upload
if (!JFile::upload($file['tmp_name'], $file['filepath'])) {
// Error in upload
JError::raiseWarning(100, JText::_('COM_JEDCHECKER_ERROR_UNABLE_TO_UPLOAD_FILE'));
return false;
}
$appl->redirect('index.php?option=com_jedchecker&view=uploads', JText::_('COM_JEDCHECKER_UPLOAD_WAS_SUCCESSFUL'));
return true;
}
return false;
}
示例13: check
/**
* Method to perform sanity checks on the JTable instance properties to ensure
* they are safe to store in the database. Child classes should override this
* method to make sure the data they are storing in the database is safe and
* as expected before storage.
*
* @return boolean True if the instance is sane and able to be stored in the database.
*
* @link http://docs.joomla.org/JTable/check
* @since 11.1
*/
public function check()
{
$input = JFactory::getApplication()->input;
$file = $input->files->get('jform', '', 'ARRAY');
$post = $input->post->get('jform', '', 'ARRAY');
$bookId = $post['book_id'];
$file = $file['audio_upload'];
if (empty($file['error'])) {
// Make the filename safe
$audioFile = JFile::makeSafe($file['name']);
$fileExt = explode('.', $audioFile);
if (isset($audioFile)) {
$filepath = JPath::clean(JPATH_SITE . '/media/englishconcept/media/audio/' . strtolower(md5($bookId . $file['name'])) . '.' . $fileExt[1]);
$objectFile = new JObject($file);
$objectFile->filepath = $filepath;
if (JFile::exists($objectFile->filepath)) {
JFile::delete($objectFile->filepath);
}
if (!JFile::upload($objectFile->tmp_name, $objectFile->filepath)) {
return false;
}
}
}
return true;
}
示例14: store
public function store($data)
{
$row =& $this->getTable('stockimage_detail');
$file = JRequest::getVar('stock_amount_image', '', 'files', 'array');
if ($_FILES['stock_amount_image']['name'] != "") {
$ext = explode(".", $file['name']);
$filetmpname = substr($file['name'], 0, strlen($file['name']) - strlen($ext[count($ext) - 1]));
$filename = JPath::clean(time() . '_' . $filetmpname . "jpg");
$row->stock_amount_image = $filename;
$src = $file['tmp_name'];
$dest = REDSHOP_FRONT_IMAGES_RELPATH . 'stockroom/' . $filename;
JFile::upload($src, $dest);
if (isset($data['stock_image']) != "" && is_file(REDSHOP_FRONT_IMAGES_RELPATH . 'stockroom/' . $data['stock_image'])) {
unlink(REDSHOP_FRONT_IMAGES_RELPATH . 'stockroom/' . $data['stock_image']);
}
}
if (!$row->bind($data)) {
$this->setError($this->_db->getErrorMsg());
return false;
}
if (!$row->store()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
return $row;
}
示例15: uploadIcon
/**
* Upload an icon for a work
*
* @param KCommandContext A command context object
* @return void
*/
public function uploadIcon(KCommandContext $context)
{
$icon = KRequest::get('files.icon', 'raw');
if (!$icon['name']) {
return;
}
//Prepare MediaHelper
JLoader::register('MediaHelper', JPATH_ROOT . '/components/com_media/helpers/media.php');
// is it an image
if (!MediaHelper::isImage($icon['name'])) {
JError::raiseWarning(21, sprintf(JText::_("%s failed to upload because it's not an image."), $icon['name']));
return;
}
// are we allowed to upload this filetype
if (!MediaHelper::canUpload($icon, $error)) {
JError::raiseWarning(21, sprintf(JText::_("%s failed to upload because %s"), $icon['name'], lcfirst($error)));
return;
}
$slug = $this->getService('koowa:filter.slug');
$path = 'images/com_portfolio/work/' . $slug->sanitize($context->data->title) . '/icon/';
$ext = JFile::getExt($icon['name']);
$name = JFile::makeSafe($slug->sanitize($context->data->title) . '.' . $ext);
JFile::upload($icon['tmp_name'], JPATH_ROOT . '/' . $path . $name);
$context->data->icon = $path . $name;
}