JFile::copy($ori_file, $target_file); stopped working in j3

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
User avatar
carsten888
Joomla! Ace
Joomla! Ace
Posts: 1224
Joined: Sat Feb 11, 2006 8:32 am
Contact:

JFile::copy($ori_file, $target_file); stopped working in j3

Post by carsten888 » Wed Jan 21, 2015 8:35 am

JFile::copy worked fine for years. But recently its behaviour has changed.

In previous versions, you just need the original file and the copy function would create the new file AND copy the content. (like the copy() function in PHP does).
In the recent version (j3.3.6), to copy a file, the new file needs to already be in the location. So you need both the original file AND the new file to be there, before the JFile::copy function can copy the content of the file.

So before copying the content of the file, you first need to create the new file. (why?!)

Problem is, what is the new syntax for creating a new file?
I can not find that in the documentation.
https://api.joomla.org/cms-3/classes/JFile.html [edit]oops wrong url[/edit]
Last edited by carsten888 on Wed Jan 21, 2015 9:31 am, edited 1 time in total.
http://www.pages-and-items.com my extensions:
User-Private-Page, Redirect-on-Login, Admin-Help-Pages, Dynamic-Menu-Links, Admin-Menu-Manager, plugin load module in article, plugin pure css tooltip and more...

User avatar
NathanHawks
Joomla! Ace
Joomla! Ace
Posts: 1900
Joined: Wed Oct 02, 2013 6:17 pm
Location: Washington state, U.S.
Contact:

Re: JFile::copy($ori_file, $target_file); stopped working in

Post by NathanHawks » Wed Jan 21, 2015 8:51 am

The API page for 3.3:
https://api.joomla.org/cms-3/classes/JFile.html

I notice JFile::move exists... I'd like to say "one presumes a move method, would not expect a destination file" ... but I'd say the same about JFile::copy if it didn't involve calling you a liar :)

To more directly answer your question, perhaps JFile::write.
Save time - hire me for your Joomla to-do list! http://nathanhawks.us/joomla

User avatar
carsten888
Joomla! Ace
Joomla! Ace
Posts: 1224
Joined: Sat Feb 11, 2006 8:32 am
Contact:

Re: JFile::copy($ori_file, $target_file); stopped working in

Post by carsten888 » Wed Jan 21, 2015 9:38 am

thanks. it is indeed 'write'.

it says:
Write contents to a file
but it also seems to create the file itself.

Code: Select all

$target_file = JPATH_ROOT.'/hello.txt';
$content = 'hello world';
JFile::write($target_file, $content);
http://www.pages-and-items.com my extensions:
User-Private-Page, Redirect-on-Login, Admin-Help-Pages, Dynamic-Menu-Links, Admin-Menu-Manager, plugin load module in article, plugin pure css tooltip and more...


Locked

Return to “Joomla! 3.x Coding”