how to delete file in joomla2.5 - joomla

I have dynamic listing page. From that I want to delete file from server using joomla2.5. I try with the following code:
jimport('joomla.filesystem.file');
$path = JPath::clean($path);
It is not working.

To delete the folder:
JFolder::delete(JPATH_ROOT.DS.'modules'.DS.'mod_footer');
To delete the File:
JFile::delete(JPATH_ROOT.DS.'modules'.DS.'mod_footer'.DS.'mod_footer.php');

Related

Delete a file from specific directory Laravel

I have some files in "public/uploads/somephoto.jpg". How to delete this file? I tried
unlink(url('/uploads/somefile.jpg'));
But it doesn't work.
if file in your public folder then
unlink(public_path('uploads/somefile.jpg'));
or if it is stored in storage folder then
unlink(storage_path('uploads/somefile.jpg'));
here url() retrun http url but for delete file edit file you need system path which will be get by storage_path() or public_path()

How to read a .docx file via PHP Word sample code in Codeigniter

Am trying to read a .docx file which is inside my project folder via PHP Word library. I have included autoloader like this :
include_once 'vendor/autoload.php'; in my controller.
CODE FOR FUNCTION IN CONTROLLER:
function test_phpword()
{
$a=base_url();
$path=$a."".'123.docx';
$source =$path;
echo date('H:i:s'), " Reading contents from `{$source}`";
$phpWord = \PhpOffice\PhpWord\IOFactory::load($source);
echo write($phpWord, basename(__FILE__, '.php'), $writers);
}
BUT GETTING ERROR LIKE BELOW:
06:18:42 Reading contents from http://localhost/myproject/123.docx
Fatal error: Uncaught Exception: Cannot find archive file. in /opt/lampp/htdocs/myproject/vendor/phpoffice/common/src/Common/XMLReader.php:51
Try this
Change
$path=$a."".'123.docx';
to
$path='123.docx';
And put 123.docx beside your php script file. make sure the two files are in the same place. Run your php script again.
If this helps and works fine you can check the file path and make proper change to your php program.
While loading the path, you have to give relative path to the doc file as shown below,
$random_name = 123.docx;
$contents = \PhpOffice\PhpWord\IOFactory::load('../uploads/'.$random_name);
I don't know whats your $base_url, but it will not work if it is absolute path like http://path/to/doc/file.
I have worked on it and tested. Hope it helps.

How to set path to file in Laravel?

I have located file in root directory of Laravel.
From controller I try to get this file like as:
$shipments = json_decode(file_get_contents("Statistics.json"), true);
But I get error.
What correct path to specify for getting file?
https://laravel.com/docs/5.0/helpers#paths
I guess you need base_path
file_get_contents(base_path().'/Statistics.json');

Laravel image upload creating folder instead of file

When I try to upload image from the form , Laravel is creating directory out of image name. Here is my basic code:
$file = Input::file("image");
$file = $file->move(public_path(). "/img/".$file->getClientOriginalName());
//file name is IPC_diagram.png
When die and dump I got this:
'/var/www/php/frbit/l4blog/public/img/IPC_diagram.png/phpvEb9zk'
Now name of image is name of new folder and image is renamed to some random php string, and placed in that folder.
What is the problem. Maybe something related to Linux specific handling of files. Also I was looking into symfony code for this, and symfony is trying to crete new folder every time file is moved but I don't understand how it is related to my code.
Thanks for help.
Do not use dot. Use comma, like this:
$name = time() . $file->getClientOriginalName();
$file->move('uploads/posts/',$name);

Reading an external yml file in symfony1.4 with doctrine

I created one yml file
$loader = sfYaml::load('/pms/config/org.yml');
print_r($loader);
I have values in the yml file
but Its printing only the file name
/pms/config/org.yml
What could be the error.
That happens when the file does not exist. You are pointing to the root dir of you server.
Try something like this to point to the root dir of your project:
$loader = sfYaml::load( sfConfig::get('sf_root_dir') . '/config/org.yml' );
print_r($loader);

Resources