(05-09-2021, 02:36 AM)InsiteFX Wrote: Here is a start of a FileHandler Library that you can start with has rename and copy file.
CodeIgniter 4 also has a File helper that you should also look at.
PHP Code:
<?php
namespace App\Libraries;
/**
* Class FileHandler
*
* @package App\Libraries
*/
class FileHandler
{
/**
* Class properties go here.
* -------------------------------------------------------------------
* public, private, protected, static and const.
*/
/**
* __construct ()
* -------------------------------------------------------------------
*
* Class Constructor
*
* NOTE: Not needed if not setting values or extending a Class.
*
*/
public function __construct()
{
}
// -------------------------------------------------------------------
/**
* renameFile ()
* -------------------------------------------------------------------
*
* renames $oldFilename to path $newFilename
*
* The rename method returns true on success or false on error.
*
* @param string $oldFilename
* @param string $newFilename
* @return bool
*/
public function renameFile(string $oldFilename = '', string $newFilename = '') : bool
{
if (empty($oldFilename) or empty($newFilename))
{
return false;
}
else
{
return rename($oldFilename, $newFilename);
}
}
// -------------------------------------------------------------------
/**
* copyFile ()
* -------------------------------------------------------------------
*
* copies $oldFilename to path $newFilename
*
* The copy method returns true on success or false on error.
*
* @param string $oldFilename
* @param string $newFilename
* @return bool
*/
public function copyFile(string $oldFilename = '', string $newFilename = '') : bool
{
if (empty($oldFilename) or empty($newFilename))
{
return false;
}
else
{
return copy($oldFilename, $newFilename);
}
}
// -------------------------------------------------------------------
} // End of FileHandler Library Class.
/**
* -----------------------------------------------------------------------
* Filename: FileHandler.php
* Location: ./app/Libraries/FileHandler.php
* -----------------------------------------------------------------------
*/
OK, Im on v3.1.9 but intend updating to v4 when the need arises, which now maybe the time. But has it been declared stable?
Where did you get that library from? I noted Location: ./app/Libraries/FileHandler.php but could not find that link anywhere.
And where do I put it?
I note that it can copy but could not see if it can paste.
I can create a path when the advert is created, then if a line in the file can be copied like this line below, then I will need to be able to paste it into a text box, or something similar that can be posted, within the category file, then the fwrite process will do the rest.
PHP Code:
<button><a/href="/adverts/$user/drink/coke">Coke</a></button>
For the system to paste it would need to open the category view page then find the word "advert" in this line
PHP Code:
<input type="text" value="<?php echo isset($_POST['advert']) ? $_POST['advert'] : '';?>"
and paste somewhere within & I dont know where. It will be important that coding not be displayed but the BUTTON is displayed.