simpsonnth Posted October 23, 2014 Share Posted October 23, 2014 Hi there, I have decided using the Joomla API however, the documentation was for 1.5 and 2.5 system only but i'm using 3.0. I have a number of files that look like this: "14-05-14 JoePharnel.pdf" and "13-05-12 HarryCollins.pdf" Basically I want to create a PHP code that when someone ftp uploads those files to the upload folder that it will 1) Create a directory if it doesn't exist using there name 2) Move the files to the correct directory (E.g. JoePharnel to the JoePharnel Directory ignoring the number at the beginning) My new code creates the folder but won't move the file in the upload into that new folder, code is below: <?phpdefine( '_JEXEC', 1);define('JPATH', dirname(__FILE__) );if (!defined('DS')){define( 'DS', DIRECTORY_SEPARATOR );$parts = explode( DS, JPATH );$script_root = implode( DS, $parts ) ;// check path$x = array_search ( 'administrator', $parts );if (!$x) exit;$path = '';for ($i=0; $i < $x; $i++){$path = $path.$parts[$i].DS; }// remove last DS$path = substr($path, 0, -1);if (!defined('JPATH_BASE')){define('JPATH_BASE', $path );} if (!defined('JPATH_SITE')){define('JPATH_SITE', $path );} /* Required Files */require_once ( JPATH_SITE . DS . 'includes' . DS . 'defines.php' );require_once ( JPATH_SITE . DS . 'includes' . DS . 'framework.php' );require_once ( JPATH_SITE . DS . 'libraries' . DS . 'joomla' . DS . 'factory.php' );//Import filesystem libraries. Perhaps not necessary, but does not hurtjimport('joomla.filesystem.path');jimport('joomla.filesystem.file');jimport('joomla.filesystem.folder');jimport('joomla.user.user');//First we set up parameters$searchpath = JPATH_BASE . DS . "upload";//Then we create the subfolder called pngif ( !JFolder::create($searchpath . DS ."Images") ) {//Throw error message and stop script}//Now we read all png files and put them in an array.$png_files = JFolder::files($searchpath,'.png');//Now we need some stuff from the JFile:: class to move all files into the new folderforeach ($png_files as $file) {JFile::move($searchpath. DS . ".png" . $file, $searchpath . DS. "Images" . $file);}//Lastly, we are moving the complete subdir to the root of the component.if (JFolder::move($searchpath . DS. "Images",JPATH_COMPONENT) ) {//Redirect with perhaps a happy message} else {//Throw an error}}?> Only error i get is Notice: Use of undefined constant JPATH_COMPONENT - assumed 'JPATH_COMPONENT' in /upload.php on line 70. I have used and adapted multiple php code so any help would be appreciated. Or if you can point me to where i can find the answer that would be brilliant Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.