Welcome Guest, Not a member yet? Register   Sign In
How to attach a file without the user being able to explore all files?
#11

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
 * -----------------------------------------------------------------------
 */ 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
RE: How to attach a file without the user being able to explore all files? - by InsiteFX - 05-09-2021, 02:36 AM



Theme © iAndrew 2016 - Forum software by © MyBB