Archived talk:Creating a file uploader in your component
From Joomla! Documentation
Hi
Implementing the SWFUpload Application demo for my component. The joomla document explains only the simple demo (http://docs.joomla.org/Creating_a_file_uploader_in_your_component )
what are the changes i have to do from the joomla doc. How i rewrite the thumbnail picture function for joomla 1.5
I tried so many time but not works out
<?php // This script accepts an ID and looks in the user's session for stored thumbnail data. // It then streams the data to the browser as an image
// Work around the Flash Player Cookie Bug if (isset($_POST["PHPSESSID"])) { session_id($_POST["PHPSESSID"]); }
session_start();
$image_id = isset($_GET["id"]) ? $_GET["id"] : false;
if ($image_id === false) { header("HTTP/1.1 500 Internal Server Error"); echo "No ID"; exit(0); }
if (!is_array($_SESSION["file_info"]) || !isset($_SESSION["file_info"][$image_id])) { header("HTTP/1.1 404 Not found"); exit(0); }
header("Content-type: image/jpeg") ; header("Content-Length: ".strlen($_SESSION["file_info"][$image_id])); echo $_SESSION["file_info"][$image_id]; exit(0); ?>
Pls help
Regards Gopi
A few comments on Part 5 and the PHP script
I changed some tests to use JFile versions and shortened the code. Return value true on success or else false if there was an error.
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
$fieldName = 'file_upload';
$fileTemp = $_FILES[$fieldName]['tmp_name'];
$fileName = JFile::makeSafe( $_FILES[$fieldName]['name'] );
$fileExt = strtolower( JFile::getExt( $fileName ) );
$imageinfo = getimagesize( $fileTemp );
$mimetypes = array( 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/gif' );
$uploadPath = JPATH_COMPONENT . DS . 'images' . DS . $fileName;
switch ( $_FILES[$fieldName]['error'] ) {
case 1:
echo JText::_( 'FILE LARGER THAN PHP INI ALLOW' );
return false;
case 2:
echo JText::_( 'FILE LARGER THAN HTML FORM ALLOW' );
return false;
case 3:
echo JText::_( 'ERROR PARTIAL UPLOAD' );
return false;
case 4:
echo JText::_( 'ERROR NO FILE' );
return false;
default:
}
if ( $_FILES[$fieldName]['size'] > 2000000 ) {
echo JText::_( 'FILE BIGGER THAN 2MB' );
}
if ( !in_array( $fileExt, explode(',', 'jpeg,jpg,png,gif') ) ) {
echo JText::_( 'INVALID EXTENSION' );
return false;
} else if ( !in_array( $imageinfo['mime'], $mimetypes ) ) {
echo JText::_( 'INVALID FILE TYPE' );
return false;
} else if ( !is_int( $imageinfo[0] ) || !is_int( $imageinfo[0] ) ) {
echo JText::_( 'INVALID FILE SIZE' );
return false;
}
if( !JFile::upload( $fileTemp, $uploadPath ) ) {
echo JText::_( 'ERROR MOVING FILE' );
return false;
}
return true;