neven Posted September 4, 2011 Share Posted September 4, 2011 Hi, I have the define(); function where i need to put the variable for directory name which is relative ... How to do that ... <?php if (TARGET_PLATFORM == FILE_SYSTEM_PLATFORM) { /** * if FILE_SYSTEM_PLATFORM is selected as TARGET_PLATFORM, * then assign root folder adress to FILE_ROOT macro */ define("FILE_ROOT", "$diro"); } public function __construct($fileRoot) { if (is_dir($fileRoot)) { $this->fileRoot = $fileRoot; //if ($this->fileRoot[strlen($this->fileRoot) - 1] != '/' ) { // $this->fileRoot .= '/'; //} } else { die($fileRoot .' is not a directory '); } } ?> When i go with this, it says this: " 'dir name ' is not a directory". But I need the variable for this to work as I want to. Does anyone have an idea? To make it clear, this is only the small part of code, which is a part of the directory root for the directory tree. Quote Link to comment https://forums.phpfreaks.com/topic/246386-how-to-define-function/ Share on other sites More sharing options...
gizmola Posted September 4, 2011 Share Posted September 4, 2011 You have not provided enough of a description of your problem nor enough code to understand what is going on. One thing I can tell you: define("FILE_ROOT", "$diro"); The quotes do nothing helpful. define("FILE_ROOT", $diro); Would be the right use. If you are hoping that this will act like a macro -- that is not how define works. It creates a constant at the point that define() is called, so FILE_ROOT will be set to whatever the value of $diro is. I'm not sure how that figures into your problem or the rest of the code that you didn't provide. Quote Link to comment https://forums.phpfreaks.com/topic/246386-how-to-define-function/#findComment-1265250 Share on other sites More sharing options...
neven Posted September 4, 2011 Author Share Posted September 4, 2011 You have not provided enough of a description of your problem nor enough code to understand what is going on. One thing I can tell you: define("FILE_ROOT", "$diro"); The quotes do nothing helpful. define("FILE_ROOT", $diro); Would be the right use. If you are hoping that this will act like a macro -- that is not how define works. It creates a constant at the point that define() is called, so FILE_ROOT will be set to whatever the value of $diro is. I'm not sure how that figures into your problem or the rest of the code that you didn't provide. Ok this is one of the files: <?php require('connecto.php'); session_start(); error_reporting(0); $id = $_GET['id']; $q = "SELECT * FROM albums WHERE $id = ideo"; $results = mysql_query($q); $data = mysql_fetch_array($results); $diro = $data['dosjeid']; $id = $data['ideo']; /************************************** * File Name: config.php * Begin: Thursday, June, 06, 2006 * Author: Ahmet Oguz Mermerkaya * Email: [email protected] ***************************************/ if (!defined("IN_PHP")) { die(); } /** * if you want to run in demo mode, enable the macro below * if it runs in demo mode, it doesn't care what TARGET_PLATFORM is */ //define("DEMO_MODE", true); /** target platform types * this script runs for both database(mysql) and file system. * database is supposed to be mysql */ define ("DATABASE_PLATFORM", 0); // Don't edit define ("FILE_SYSTEM_PLATFORM", 1); // Don't edit /** * choose target platform according to your needs * it may be DATABASE_PLATFORM or FILE_SYSTEM_PLATFORM */ define ("TARGET_PLATFORM", FILE_SYSTEM_PLATFORM); if (TARGET_PLATFORM == FILE_SYSTEM_PLATFORM) { /** * if FILE_SYSTEM_PLATFORM is selected as TARGET_PLATFORM, * then assign root folder adress to FILE_ROOT macro */ define("FILE_ROOT", "store"); } else if (TARGET_PLATFORM == DATABASE_PLATFORM) { /** * if DATABASE_PLATFORM is selected as TARGET_PLATFORM, * set the variables to connect database and * set the TREE_TABLE_PREFIX if you want to * change the prefix of table name */ // set database host $dbHost = "localhost"; //set database user name $dbUsername = "root"; // set password to connect to database $dbPassword = "21236161"; // set database name $dbName = "php"; // set database table prefix define ("TREE_TABLE_PREFIX", "tree"); } else { die("No known target platform specified, in includes/config.php"); } define ("SUCCESS", 1); // Don't edit define ("FAILED", -1); // Don't edit define ("FAILED_FILE_WITH_SAME_NAME_EXIST", -2); // Don't edit, it is only used in FILE_SYSTEM_PLATFORM error_reporting(0); ?> Quote Link to comment https://forums.phpfreaks.com/topic/246386-how-to-define-function/#findComment-1265251 Share on other sites More sharing options...
neven Posted September 4, 2011 Author Share Posted September 4, 2011 You have not provided enough of a description of your problem nor enough code to understand what is going on. One thing I can tell you: define("FILE_ROOT", "$diro"); The quotes do nothing helpful. define("FILE_ROOT", $diro); Would be the right use. If you are hoping that this will act like a macro -- that is not how define works. It creates a constant at the point that define() is called, so FILE_ROOT will be set to whatever the value of $diro is. I'm not sure how that figures into your problem or the rest of the code that you didn't provide. This the second file : <?php require('connecto.php'); session_start(); error_reporting(0); $id = $_GET['id']; $q = "SELECT * FROM albums WHERE $id = ideo"; $results = mysql_query($q); $data = mysql_fetch_array($results); $diro = $data['dosjeid']; $id = $data['ideo']; /************************************** File Name: DemoTreeManager.php Begin: Wednesday, April, 15, 2009, 21:49 Author: Ozan Koroglu Ahmet Oguz Mermerkaya Email: [email protected] [email protected] ***************************************/ require_once("ITreeManager.php"); class FileTreeManager implements ITreeManager { private $fileRoot; const FOLDER_SEPARATOR = "FOLDER_SEPARATOR"; const DEFAULT_FOLDER_SEPARATOR = "/"; public function __construct($fileRoot) { if (is_dir($fileRoot)) { $this->fileRoot = $fileRoot; //if ($this->fileRoot[strlen($this->fileRoot) - 1] != '/' ) { // $this->fileRoot .= '/'; //} } else { die($fileRoot .' is not a directory '); } } public function insertElement($name, $ownerEl, $slave) { $realOwnerEl = str_replace(self::FOLDER_SEPARATOR, self::DEFAULT_FOLDER_SEPARATOR, $ownerEl); $fullPath = $this->getFullPath($realOwnerEl. self::DEFAULT_FOLDER_SEPARATOR . $name); $out = FAILED; if (file_exists($fullPath) === true) { $out = FAILED_FILE_WITH_SAME_NAME_EXIST; } else { if ($slave == 1) { if (touch($fullPath) === true) { $out = '({ "elementId":"'. $ownerEl . self::FOLDER_SEPARATOR . $name . '", "elementName":"'.$name.'", "slave":"'.$slave.'"})'; } } else{ if (mkdir($fullPath, 0755)) { $out = '({ "elementId":"'. $ownerEl . self::FOLDER_SEPARATOR . $name .'", "elementName":"'.$name.'", "slave":"'.$slave.'"})'; } } } return $out; } private function getFullPath($relativePath) { return $this->fileRoot . self::DEFAULT_FOLDER_SEPARATOR . $relativePath; } public function getElementList($ownerEl, $pageName) { $realOwnerEl = str_replace(self::FOLDER_SEPARATOR, self::DEFAULT_FOLDER_SEPARATOR, $ownerEl); $fullPath = $this->getFullPath($realOwnerEl); $str = null; if (is_dir($fullPath) && $handle = opendir($fullPath)) { $fileStr = null; /* This is the correct way to loop over the directory. */ while (false !== ($file = readdir($handle))) { if ($file == '.' || $file == '..' || $file == 'Thumbs.db'){ continue; } $supp = NULL; if (is_dir($fullPath . "/" . $file)) { $supp = "<ul class='ajax'>" ."<li id='". $ownerEl. self::FOLDER_SEPARATOR . $file ."'>{url:".$pageName."?action=getElementList&ownerEl=". $ownerEl. self::FOLDER_SEPARATOR . $file ."}</li>" ."</ul>"; } $fileStr[] .= "<li class='text' id='". $ownerEl. self::FOLDER_SEPARATOR . $file."'>" ."<span>$file</span> <a href='".$fullPath."/".$file."'>View the file</a>" . $supp ."</li>"; } closedir($handle); if ($fileStr != null) { sort($fileStr); $str = implode($fileStr); } } return $str; } public function updateElementName($name, $elementId,$ownerEl) { $ownerEl = str_replace(self::FOLDER_SEPARATOR, self::DEFAULT_FOLDER_SEPARATOR, $ownerEl); $newElementId = $ownerEl . self::DEFAULT_FOLDER_SEPARATOR . $name; $elementId = str_replace(self::FOLDER_SEPARATOR, self::DEFAULT_FOLDER_SEPARATOR, $elementId); $realElementId = $ownerEl . self::DEFAULT_FOLDER_SEPARATOR . substr($elementId, strrpos($elementId, "/"), strlen($elementId)); $fullPath = $this->getFullPath($realElementId); //$newElementId = substr($realElementId, 0, strrpos($realElementId, "/")). "/" . $name; $newFullPath = $this->getFullPath($newElementId); $out = FAILED; if (file_exists($newFullPath) === true && dirname($fullPath) != dirname($newFullPath) ) { $out = FAILED_FILE_WITH_SAME_NAME_EXIST; } else if (rename($fullPath, $newFullPath) == true) { $newRealElementId = str_replace(self::DEFAULT_FOLDER_SEPARATOR, self::FOLDER_SEPARATOR, $newElementId); $out = '({"elementName":"'.$name.'", "elementId":"'. $newRealElementId .'"})'; } return $out; } public function deleteElement($elementId, &$index = 0, $ownerEl) { $elementId = str_replace(self::FOLDER_SEPARATOR, self::DEFAULT_FOLDER_SEPARATOR, $elementId); $elementId = str_replace(self::FOLDER_SEPARATOR, self::DEFAULT_FOLDER_SEPARATOR, $ownerEl) . self::DEFAULT_FOLDER_SEPARATOR . substr($elementId, strrpos($elementId, "/"), strlen($elementId)); $fullPath = $this->getFullPath($elementId); $out = FAILED; if (is_dir($fullPath) && $this->delete_recursive_dirs($fullPath)) { $out = SUCCESS; } else if (unlink($fullPath)) { $out = SUCCESS; } return $out; } public function changeOrder($elementId, $oldOwnerEl, $destOwnerEl, $destPosition) { $oldOwnerEl = str_replace(self::FOLDER_SEPARATOR, self::DEFAULT_FOLDER_SEPARATOR, $oldOwnerEl); $elementId = str_replace(self::FOLDER_SEPARATOR, self::DEFAULT_FOLDER_SEPARATOR, $elementId); $realElementId = $oldOwnerEl . self::DEFAULT_FOLDER_SEPARATOR . substr($elementId, strrpos($elementId, "/"), strlen($elementId)); $fullPath = $this->getFullPath($realElementId); $elementName = substr($realElementId, strrpos($realElementId, "/")+1); // plus 1 not to get / character $realDestOwnerEl = str_replace(self::FOLDER_SEPARATOR, self::DEFAULT_FOLDER_SEPARATOR, $destOwnerEl); $newFullPath = $this->getFullPath($realDestOwnerEl . "/". $elementName); $newElementId = $destOwnerEl . self::FOLDER_SEPARATOR . $elementName; $out = FAILED; if (file_exists($newFullPath) === true && dirname($fullPath) != dirname($newFullPath)) { $out = FAILED_FILE_WITH_SAME_NAME_EXIST; } else if (rename($fullPath, $newFullPath) == true) { $out = '({"oldElementId":"'. str_replace(self::DEFAULT_FOLDER_SEPARATOR, self::FOLDER_SEPARATOR, $elementId) .'", "elementId":"'. $newElementId .'"})';; } return $out; } public function getRootId(){ return self::FOLDER_SEPARATOR; } private function delete_recursive_dirs($dirname) { // recursive function to delete // all subdirectories and contents: if(is_dir($dirname)) { $dir_handle=opendir($dirname); } while($file=readdir($dir_handle)) { if($file!="." && $file!="..") { if(!is_dir($dirname."/".$file)){ unlink ($dirname."/".$file); } else { $this->delete_recursive_dirs($dirname."/".$file); } } } closedir($dir_handle); rmdir($dirname); return true; } } ?> So this is wher the file directory $diro can't pass. Quote Link to comment https://forums.phpfreaks.com/topic/246386-how-to-define-function/#findComment-1265253 Share on other sites More sharing options...
neven Posted September 4, 2011 Author Share Posted September 4, 2011 You have not provided enough of a description of your problem nor enough code to understand what is going on. One thing I can tell you: define("FILE_ROOT", "$diro"); The quotes do nothing helpful. define("FILE_ROOT", $diro); Would be the right use. If you are hoping that this will act like a macro -- that is not how define works. It creates a constant at the point that define() is called, so FILE_ROOT will be set to whatever the value of $diro is. I'm not sure how that figures into your problem or the rest of the code that you didn't provide. Apologize for that ...I am new ...sou I'm getting used to ... Quote Link to comment https://forums.phpfreaks.com/topic/246386-how-to-define-function/#findComment-1265254 Share on other sites More sharing options...
gizmola Posted September 4, 2011 Share Posted September 4, 2011 Ok, well I can see the intention of these constants is to use either a db or some filesystem based storage. Since you're using filesystem storage it appears that define("FILE_ROOT", "store"); Needs to be the directory path to the place where whatever is being stored, will be stored, you need an actual operating system specific path -- something like: define("FILE_ROOT", "/home/someuser/public_html/store"); I have no idea what this variable should be, and this is based on the assumption this constant gets passed to constructor for the object of whatever class you partially pasted. If that assumption is correct, then this needs to be a real path, and not just some relative variable like "store". Quote Link to comment https://forums.phpfreaks.com/topic/246386-how-to-define-function/#findComment-1265255 Share on other sites More sharing options...
gizmola Posted September 4, 2011 Share Posted September 4, 2011 I see you posted more code, but I don't have time to look through an entire class. Try my suggestion and see if that fixes things, as I think it might. Quote Link to comment https://forums.phpfreaks.com/topic/246386-how-to-define-function/#findComment-1265256 Share on other sites More sharing options...
neven Posted September 4, 2011 Author Share Posted September 4, 2011 I see you posted more code, but I don't have time to look through an entire class. Try my suggestion and see if that fixes things, as I think it might. Ok i understand what is the real path ... it works with real path and it shows me all directorys in that path ...but i need the variable. so that when user won't see the directory . He seas only one directory that he own by id or in this case $diro variable... UNDERSTAND ? so how can I doo that with this script ? If you can giv me some opinion ...please regards . Quote Link to comment https://forums.phpfreaks.com/topic/246386-how-to-define-function/#findComment-1265257 Share on other sites More sharing options...
gizmola Posted September 4, 2011 Share Posted September 4, 2011 As far as I can see, if you have a variable that contains the path to the user's home/base directory, then setting that in the define will work. It needs to be the full path to that directory however. Quote Link to comment https://forums.phpfreaks.com/topic/246386-how-to-define-function/#findComment-1265265 Share on other sites More sharing options...
neven Posted September 4, 2011 Author Share Posted September 4, 2011 As far as I can see, if you have a variable that contains the path to the user's home/base directory, then setting that in the define will work. It needs to be the full path to that directory however. Jes I understand, I have tryed this: define("FILE_ROOT", "store/".$diro); But it does not show me the files in the folder of that user "$diro" he shows me only the folders... Do you have an idea have to go around that ....? If you understand what I am trying to do.. Quote Link to comment https://forums.phpfreaks.com/topic/246386-how-to-define-function/#findComment-1265269 Share on other sites More sharing options...
neven Posted September 4, 2011 Author Share Posted September 4, 2011 As far as I can see, if you have a variable that contains the path to the user's home/base directory, then setting that in the define will work. It needs to be the full path to that directory however. I have also tried to put the directory in front of the variable: define("FILE_ROOT", "store/".$diro."/Folder"); But then it say "store/65465/Folder is not a directory " ???????????? I'm confused :S Quote Link to comment https://forums.phpfreaks.com/topic/246386-how-to-define-function/#findComment-1265271 Share on other sites More sharing options...
neven Posted September 4, 2011 Author Share Posted September 4, 2011 Do anyone have a IDEA how to go around this problem ? I don't know what can I use instead of this funcTion: define("FILE_ROOT", "store/".$diro."/Folder"); For this script: <?php require('connecto.php'); session_start(); error_reporting(0); $id = $_GET['id']; $q = "SELECT * FROM albums WHERE $id = ideo"; $results = mysql_query($q); $data = mysql_fetch_array($results); $diro = $data['dosjeid']; $id = $data['ideo']; /************************************** * File Name: config.php * Begin: Thursday, June, 06, 2006 * Author: Ahmet Oguz Mermerkaya * Email: [email protected] ***************************************/ if (!defined("IN_PHP")) { die(); } /** * if you want to run in demo mode, enable the macro below * if it runs in demo mode, it doesn't care what TARGET_PLATFORM is */ //define("DEMO_MODE", true); /** target platform types * this script runs for both database(mysql) and file system. * database is supposed to be mysql */ define ("DATABASE_PLATFORM", 0); // Don't edit define ("FILE_SYSTEM_PLATFORM", 1); // Don't edit /** * choose target platform according to your needs * it may be DATABASE_PLATFORM or FILE_SYSTEM_PLATFORM */ define ("TARGET_PLATFORM", FILE_SYSTEM_PLATFORM); if (TARGET_PLATFORM == FILE_SYSTEM_PLATFORM) { /** * if FILE_SYSTEM_PLATFORM is selected as TARGET_PLATFORM, * then assign root folder adress to FILE_ROOT macro */ $diro = $data['dosjeid']; //this is the problem with this I GET THIS MESAGE ---------"6546 IS NOT THE DIRECTORY" define("FILE_ROOT", $diro); } else if (TARGET_PLATFORM == DATABASE_PLATFORM) { /** * if DATABASE_PLATFORM is selected as TARGET_PLATFORM, * set the variables to connect database and * set the TREE_TABLE_PREFIX if you want to * change the prefix of table name */ // set database host $dbHost = "localhost"; //set database user name $dbUsername = "root"; // set password to connect to database $dbPassword = "21236161"; // set database name $dbName = "php"; // set database table prefix define ("TREE_TABLE_PREFIX", "tree"); } else { die("No known target platform specified, in includes/config.php"); } define ("SUCCESS", 1); // Don't edit define ("FAILED", -1); // Don't edit define ("FAILED_FILE_WITH_SAME_NAME_EXIST", -2); // Don't edit, it is only used in FILE_SYSTEM_PLATFORM error_reporting(0); ?> This is the second script from where I get the eror mesage!! <?php require('connecto.php'); session_start(); error_reporting(0); $id = $_GET['id']; $q = "SELECT * FROM albums WHERE $id = ideo"; $results = mysql_query($q); $data = mysql_fetch_array($results); $diro = $data['dosjeid']; $id = $data['ideo']; /************************************** File Name: DemoTreeManager.php Begin: Wednesday, April, 15, 2009, 21:49 Author: Ozan Koroglu Ahmet Oguz Mermerkaya Email: [email protected] [email protected] ***************************************/ require_once("ITreeManager.php"); class FileTreeManager implements ITreeManager { private $fileRoot; const FOLDER_SEPARATOR = "FOLDER_SEPARATOR"; const DEFAULT_FOLDER_SEPARATOR = "/"; public function __construct($fileRoot) { if (is_dir($fileRoot)) { $this->fileRoot = $fileRoot; //if ($this->fileRoot[strlen($this->fileRoot) - 1] != '/' ) { // $this->fileRoot .= '/'; //} } else { die($fileRoot .' is not a directory '); } } public function insertElement($name, $ownerEl, $slave) { $realOwnerEl = str_replace(self::FOLDER_SEPARATOR, self::DEFAULT_FOLDER_SEPARATOR, $ownerEl); $fullPath = $this->getFullPath($realOwnerEl. self::DEFAULT_FOLDER_SEPARATOR . $name); $out = FAILED; if (file_exists($fullPath) === true) { $out = FAILED_FILE_WITH_SAME_NAME_EXIST; } else { if ($slave == 1) { if (touch($fullPath) === true) { $out = '({ "elementId":"'. $ownerEl . self::FOLDER_SEPARATOR . $name . '", "elementName":"'.$name.'", "slave":"'.$slave.'"})'; } } else{ if (mkdir($fullPath, 0755)) { $out = '({ "elementId":"'. $ownerEl . self::FOLDER_SEPARATOR . $name .'", "elementName":"'.$name.'", "slave":"'.$slave.'"})'; } } } return $out; } private function getFullPath($relativePath) { return $this->fileRoot . self::DEFAULT_FOLDER_SEPARATOR . $relativePath; } public function getElementList($ownerEl, $pageName) { $realOwnerEl = str_replace(self::FOLDER_SEPARATOR, self::DEFAULT_FOLDER_SEPARATOR, $ownerEl); $fullPath = $this->getFullPath($realOwnerEl); $str = null; if (is_dir($fullPath) && $handle = opendir($fullPath)) { $fileStr = null; /* This is the correct way to loop over the directory. */ while (false !== ($file = readdir($handle))) { if ($file == '.' || $file == '..' || $file == 'Thumbs.db'){ continue; } $supp = NULL; if (is_dir($fullPath . "/" . $file)) { $supp = "<ul class='ajax'>" ."<li id='". $ownerEl. self::FOLDER_SEPARATOR . $file ."'>{url:".$pageName."?action=getElementList&ownerEl=". $ownerEl. self::FOLDER_SEPARATOR . $file ."}</li>" ."</ul>"; } $fileStr[] .= "<li class='text' id='". $ownerEl. self::FOLDER_SEPARATOR . $file."'>" ."<span>$file</span> <a href='".$fullPath."/".$file."'>View the file</a>" . $supp ."</li>"; } closedir($handle); if ($fileStr != null) { sort($fileStr); $str = implode($fileStr); } } return $str; } public function updateElementName($name, $elementId,$ownerEl) { $ownerEl = str_replace(self::FOLDER_SEPARATOR, self::DEFAULT_FOLDER_SEPARATOR, $ownerEl); $newElementId = $ownerEl . self::DEFAULT_FOLDER_SEPARATOR . $name; $elementId = str_replace(self::FOLDER_SEPARATOR, self::DEFAULT_FOLDER_SEPARATOR, $elementId); $realElementId = $ownerEl . self::DEFAULT_FOLDER_SEPARATOR . substr($elementId, strrpos($elementId, "/"), strlen($elementId)); $fullPath = $this->getFullPath($realElementId); //$newElementId = substr($realElementId, 0, strrpos($realElementId, "/")). "/" . $name; $newFullPath = $this->getFullPath($newElementId); $out = FAILED; if (file_exists($newFullPath) === true && dirname($fullPath) != dirname($newFullPath) ) { $out = FAILED_FILE_WITH_SAME_NAME_EXIST; } else if (rename($fullPath, $newFullPath) == true) { $newRealElementId = str_replace(self::DEFAULT_FOLDER_SEPARATOR, self::FOLDER_SEPARATOR, $newElementId); $out = '({"elementName":"'.$name.'", "elementId":"'. $newRealElementId .'"})'; } return $out; } public function deleteElement($elementId, &$index = 0, $ownerEl) { $elementId = str_replace(self::FOLDER_SEPARATOR, self::DEFAULT_FOLDER_SEPARATOR, $elementId); $elementId = str_replace(self::FOLDER_SEPARATOR, self::DEFAULT_FOLDER_SEPARATOR, $ownerEl) . self::DEFAULT_FOLDER_SEPARATOR . substr($elementId, strrpos($elementId, "/"), strlen($elementId)); $fullPath = $this->getFullPath($elementId); $out = FAILED; if (is_dir($fullPath) && $this->delete_recursive_dirs($fullPath)) { $out = SUCCESS; } else if (unlink($fullPath)) { $out = SUCCESS; } return $out; } public function changeOrder($elementId, $oldOwnerEl, $destOwnerEl, $destPosition) { $oldOwnerEl = str_replace(self::FOLDER_SEPARATOR, self::DEFAULT_FOLDER_SEPARATOR, $oldOwnerEl); $elementId = str_replace(self::FOLDER_SEPARATOR, self::DEFAULT_FOLDER_SEPARATOR, $elementId); $realElementId = $oldOwnerEl . self::DEFAULT_FOLDER_SEPARATOR . substr($elementId, strrpos($elementId, "/"), strlen($elementId)); $fullPath = $this->getFullPath($realElementId); $elementName = substr($realElementId, strrpos($realElementId, "/")+1); // plus 1 not to get / character $realDestOwnerEl = str_replace(self::FOLDER_SEPARATOR, self::DEFAULT_FOLDER_SEPARATOR, $destOwnerEl); $newFullPath = $this->getFullPath($realDestOwnerEl . "/". $elementName); $newElementId = $destOwnerEl . self::FOLDER_SEPARATOR . $elementName; $out = FAILED; if (file_exists($newFullPath) === true && dirname($fullPath) != dirname($newFullPath)) { $out = FAILED_FILE_WITH_SAME_NAME_EXIST; } else if (rename($fullPath, $newFullPath) == true) { $out = '({"oldElementId":"'. str_replace(self::DEFAULT_FOLDER_SEPARATOR, self::FOLDER_SEPARATOR, $elementId) .'", "elementId":"'. $newElementId .'"})';; } return $out; } public function getRootId(){ return self::FOLDER_SEPARATOR; } private function delete_recursive_dirs($dirname) { // recursive function to delete // all subdirectories and contents: if(is_dir($dirname)) { $dir_handle=opendir($dirname); } while($file=readdir($dir_handle)) { if($file!="." && $file!="..") { if(!is_dir($dirname."/".$file)){ unlink ($dirname."/".$file); } else { $this->delete_recursive_dirs($dirname."/".$file); } } } closedir($dir_handle); rmdir($dirname); return true; } } ?> Can anyone HELP? Quote Link to comment https://forums.phpfreaks.com/topic/246386-how-to-define-function/#findComment-1265389 Share on other sites More sharing options...
gizmola Posted September 4, 2011 Share Posted September 4, 2011 As far as I can see, if you have a variable that contains the path to the user's home/base directory, then setting that in the define will work. It needs to be the full path to that directory however. I have also tried to put the directory in front of the variable: define("FILE_ROOT", "store/".$diro."/Folder"); But then it say "store/65465/Folder is not a directory " ???????????? I'm confused :S You can not use a relative directory there "store". You need to provide a real path -> "/some/path/store". Quote Link to comment https://forums.phpfreaks.com/topic/246386-how-to-define-function/#findComment-1265444 Share on other sites More sharing options...
neven Posted September 4, 2011 Author Share Posted September 4, 2011 As far as I can see, if you have a variable that contains the path to the user's home/base directory, then setting that in the define will work. It needs to be the full path to that directory however. I have also tried to put the directory in front of the variable: define("FILE_ROOT", "store/".$diro."/Folder"); But then it say "store/65465/Folder is not a directory " ???????????? I'm confused :S You can not use a relative directory there "store". You need to provide a real path -> "/some/path/store". Ok I know that with real path it works ....Like this define("FILE_ROOT", "/Web server/xampp/htdocs/store/"); But WHAT IF I NEED THE VARIABLE $value that is stored in the data base ? Instead of the the real path ??? That is bothering mee I need the variable inside of the FILE_ROOT ...Becose the name of the directory is the value that is stored in the database ! Understand???? Quote Link to comment https://forums.phpfreaks.com/topic/246386-how-to-define-function/#findComment-1265448 Share on other sites More sharing options...
neven Posted September 4, 2011 Author Share Posted September 4, 2011 As far as I can see, if you have a variable that contains the path to the user's home/base directory, then setting that in the define will work. It needs to be the full path to that directory however. I have also tried to put the directory in front of the variable: define("FILE_ROOT", "store/".$diro."/Folder"); But then it say "store/65465/Folder is not a directory " ???????????? I'm confused :S You can not use a relative directory there "store". You need to provide a real path -> "/some/path/store". Also it works with this : define("FILE_ROOT", "store" ); But when I put the variable like this: define("FILE_ROOT", "store/".$variable ); Then it does't ... I'm wondering how to put the variable value in this FILE_ROOT or is ther some other way to doo that ?? Quote Link to comment https://forums.phpfreaks.com/topic/246386-how-to-define-function/#findComment-1265450 Share on other sites More sharing options...
gizmola Posted September 5, 2011 Share Posted September 5, 2011 You might try this: define('FILE_ROOT', 'store' . self::FOLDER_SEPARATOR . $variable); However, the FILE_ROOT must be a path to a directory that apache has the rights to. It's about as simple as it gets. I don't think there is any point in my continuing to repeat the same thing in this thread. Quote Link to comment https://forums.phpfreaks.com/topic/246386-how-to-define-function/#findComment-1265503 Share on other sites More sharing options...
neven Posted September 5, 2011 Author Share Posted September 5, 2011 You might try this: define('FILE_ROOT', 'store' . self::FOLDER_SEPARATOR . $variable); However, the FILE_ROOT must be a path to a directory that apache has the rights to. It's about as simple as it gets. I don't think there is any point in my continuing to repeat the same thing in this thread. Thanks man for the answers I am greatful . I have tried this. $diro is the name of the directory That name is also stored in the data base from where I am geting the variable, 'htdocs/store' is the real path to the $diro directory ....But no luck I don't get even the error with this ... define('FILE_ROOT', 'htdocs/store' . self::FOLDER_SEPARATOR . $diro); Quote Link to comment https://forums.phpfreaks.com/topic/246386-how-to-define-function/#findComment-1265506 Share on other sites More sharing options...
gizmola Posted September 5, 2011 Share Posted September 5, 2011 neven, 'htdocs/store' is not the real path to anything. That is a relative path. It will only work if the script that is running that code has a subdirectory of htdocs. If you don't have a / at the front of the path it is a relative path. Also, it appears you testing this on a windows machine, and the directory seperator for windows is different from unix. That is why I suggested teh use of self:FOLDER_SEPERATOR. This is really a simple concept, and if you don't understand it, you are not going to get this working. At this point, I don't have any other suggestions for you -- perhaps you should pay someone to get it setup for you, because really, anyone who understands the idea would be able to get this working with very little effort. I'm not getting enough information from you to continue to try and debug it for you, and this isn't really of value to the community at large, because you are trying to modify a script that was written by someone else for your own purposes, and those purposes aren't really clear. Quote Link to comment https://forums.phpfreaks.com/topic/246386-how-to-define-function/#findComment-1265510 Share on other sites More sharing options...
neven Posted September 5, 2011 Author Share Posted September 5, 2011 neven, 'htdocs/store' is not the real path to anything. That is a relative path. It will only work if the script that is running that code has a subdirectory of htdocs. If you don't have a / at the front of the path it is a relative path. Also, it appears you testing this on a windows machine, and the directory seperator for windows is different from unix. That is why I suggested teh use of self:FOLDER_SEPERATOR. This is really a simple concept, and if you don't understand it, you are not going to get this working. At this point, I don't have any other suggestions for you -- perhaps you should pay someone to get it setup for you, because really, anyone who understands the idea would be able to get this working with very little effort. I'm not getting enough information from you to continue to try and debug it for you, and this isn't really of value to the community at large, because you are trying to modify a script that was written by someone else for your own purposes, and those purposes aren't really clear. U are right... Thanks .Unti now I haven't modify someone else script ...Lesson learned. Quote Link to comment https://forums.phpfreaks.com/topic/246386-how-to-define-function/#findComment-1265513 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.