i.e. among other things the user is picking a file name and then this is being posted to the server.
Not much I'm doing seems to work, but it does update the record
Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Code: Select all
$file = JRequest::getVar( 'calendar', '', 'files', 'array' );
$filename = '';
if(isset($file) && is_array($file) && $file['name'] != '')
{
$fullfilename = JPATH_SITE . DS . 'components' . DS . $option . DS . 'calendars' . DS . strtolower($file['name']);
$filename = strtolower($file['name']);
jimport('joomla.filesystem.file');
if (JFile::exists($fullfilename)) {
$mainframe->redirect("index.php?option=$option", "Upload failed, file already exists.");
return;
}
if (!JFile::upload($file['tmp_name'], $fullfilename)) {
$mainframe->redirect("index.php?option=$option", "Upload failed, check to make sure that /components/$option/calendars exists.");
return;
}
}
Code: Select all
if(isset($_POST['adminForm']) && $_FILES['hotbit_image']['size'] > 0)
{
$fileName = $_FILES['hotbit_image']['name'];
$tmpName = $_FILES['hotbit_image']['tmp_name'];
$fileSize = $_FILES['hotbit_image']['size'];
$fileType = $_FILES['hotbit_image']['type'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
$row->hotbit_image = $content;
$row->hotbit_image_size = $filesize;
$row->hotbit_image_type = $filetype;
}
if (!$row->store())
{
echo "<script> alert('".$row->getError()."');
window.history.go(-1); </script>\n";
exit();
}Code: Select all
$fileName = $_FILES['hotbit_image']['name'];
$tmpName = $_FILES['hotbit_image']['tmp_name'];
$fileSize = $_FILES['hotbit_image']['size'];
$fileType = $_FILES['hotbit_image']['type'];
$content = file_get_contents($tmpName);
$content = addslashes($content);
//$fileName = addslashes($fileName);
Hi thanks for the reply. I did look into this module and also read up on the framework, but the quickest solution was to use the one above.CirTap wrote: Hi,
just for the records...
The Framework equivalent of
$_FILES['hotbit_image']
is
JRequest::getVar( 'hotbit_image', '', 'files', 'array' );
another good example of how this is used can be found in the upload facility of the Media Manager
/administrator/components/com_media/controllers/file.php -> MediaControllerFile::upload()
In this file you'll also see how the FTP layer is used to copy files in case PHP suffers from insufficent access rights.
Have fun,
CirTap
do you use JDocumentHTML or JDocumentRAW ? The latter has a method called setMimeEncoding().doctorD wrote: It would be nice to have a 100% internal Joomla solution, but it was sending the html header that stumped me here, easier just to do it the 'old' way.
Interesting, but when pulling the data back out and putting into an img tag will it actually display an image? I'm not sure this would be the case. Might experiment with t.CirTap wrote:do you use JDocumentHTML or JDocumentRAW ? The latter has a method called setMimeEncoding().doctorD wrote: It would be nice to have a 100% internal Joomla solution, but it was sending the html header that stumped me here, easier just to do it the 'old' way.
http://api.joomla.org/Joomla-Framework/ ... meEncoding
Just a thought.
Have fun,
CirTap

Code: Select all
On systems which differentiate between binary and text files (i.e. Windows) the file must be opened
with 'b' included in fopen() mode parameter.
<?php
$filename = "c:\\files\\somepic.gif";
$handle = fopen($filename, "rb");
$contents = fread($handle, filesize($filename));
fclose($handle);
?>
Warning
When reading from anything that is not a regular local file, such as streams returned when reading remote files
or from popen() and fsockopen(), reading will stop after a packet is available.
This means that you should collect the data together in chunks as shown in the examples below.
<?php
// For PHP 5 and up
$handle = fopen("http://www.example.com/", "rb");
$contents = stream_get_contents($handle);
fclose($handle);
?>
<?php
$handle = fopen("http://www.example.com/", "rb");
$contents = '';
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
?>
Note: If you just want to get the contents of a file into a string, use file_get_contents() as it has much better performance than the code above.
Yep that's what I did in the end, worked exceptionally well.jalil wrote: Note: If you just want to get the contents of a file into a string, use file_get_contents() as it has much better performance than the code above.

YAHOO !!!doctorD wrote:Yep that's what I did in the end, worked exceptionally well.jalil wrote: Note: If you just want to get the contents of a file into a string, use file_get_contents() as it has much better performance than the code above.
You can also just add format=raw onto the query string, so you get:CirTap wrote: Hi,
not sure I understand what you're trying to do
So you get this uploaded file, it's stuffed into the database (BLOB presumably), and later you want to display the file (or in one go?)
As you can't put data into an tag (at least not cross-browser via the data: url schema) the src attribute of that would need to point to an URL that delivers a Content-type: image/blabla and all that stuff
Something like
Whatever that URL is, your Controller would have some"preview" task, create a JDocumentRAW for the "image layout", puts the binary data into the document's $buffer, and sends this "document".
In theory
There's no area in J! I know of where binaries are used in that way.
Intresting things you're doing, Dr.
Have fun,
CirTap
Is this also true for any custom component, or is it just an implied "feature" of the core components, esp. com_content?ianmac wrote: You can also just add format=raw onto the query string, so you get:
Code: Select all
function &_createDocument()
{
jimport('joomla.document.document');
jimport('joomla.environment.request');
$lang =& JFactory::getLanguage();
//Keep backwards compatibility with Joomla! 1.0
$raw = JRequest::getBool('no_html');
$type = JRequest::getWord('format', $raw ? 'raw' : 'html');
$attributes = array (
'charset' => 'utf-8',
'lineend' => 'unix',
'tab' => ' ',
'language' => $lang->getTag(),
'direction' => $lang->isRTL() ? 'rtl' : 'ltr'
);
$doc =& JDocument::getInstance($type, $attributes);
return $doc;
}
Code: Select all
function display($cachable=false)
{
$document =& JFactory::getDocument();
$viewType = $document->getType();
$viewName = JRequest::getCmd( 'view', $this->_name );
$viewLayout = JRequest::getCmd( 'layout', 'default' );
$view = & $this->getView( $viewName, $viewType);
// Get/Create the model
if ($model = & $this->getModel($viewName)) {
// Push the model into the view (as default)
$view->setModel($model, true);
}
// Set the layout
$view->setLayout($viewLayout);
// Display the view
if ($cachable) {
global $option;
$cache =& JFactory::getCache($option, 'view');
$cache->get($view, 'display');
} else {
$view->display();
}
}
Code: Select all
function _displayImage($tpl)
{
global $mainframe;
//code for checking user
$e1 =& $this->get('data');
$this->assignRef('filesize', $e1->filesize);
$this->assignRef('filetype', $e1->filetype);
$this->assignRef('flogo', $e1->flogo);
parent::display($tpl);
}
Code: Select all
<?php
defined('_JEXEC') or die('Restricted Access.');
header("Content-Length: $this->filesize");
header("Content-Type: $this->filetype");
header("Content-Description: PHP Generated Data");
echo $this->flogo;
?>
Code: Select all
function getLogoFile($userfile)
{
jimport('joomla.filesystem.file');
$logo = JFile::read($userfile['tmp_name']);
//$logo = file_get_contents($userfile['tmp_name']);
//**********
//$logo = addslashes($logo);
//**********
return $logo;
}