*Most Powerful Pony!* Posted February 17, 2014 Posted February 17, 2014 There is a link leading to the file, need download it, and put it in the page How this can be done using the correct API?
*Most Powerful Pony!* Posted February 17, 2014 Author Posted February 17, 2014 Good! Just show me how to get the path to the server folder assets through API, and show me where the class description PagefilesManager
kongondo Posted February 17, 2014 Posted February 17, 2014 Path http://processwire.com/api/variables/config/ E.g.: $config->urls->assets PagefilesManager class http://processwire.com/apigen/class-PagefilesManager.html Save pages via API (including images...) http://processwire.com/api/variables/pages/ 2
Valery Posted February 17, 2014 Posted February 17, 2014 Hey, Here's a snippet that does the job for me. $file_source = 'http://www.openbsd.org/images/puffy54.gif'; $file_content = file_get_contents($file_source); $target_page_id = '9999'; // replace with a real id $target_page = $pages->get($target_page_id); $target_page->of(false); $file_target = $config->paths->files . $target_page_id . '/' . 'puffy54.gif'; // or do basename() on $file_source file_put_contents($file_target, $file_content); $file_field_name = 'attachment'; $target_page->$file_field_name->add($file_target); $target_page->save(); 5
*Most Powerful Pony!* Posted February 17, 2014 Author Posted February 17, 2014 Velery it's good $file_target = $config->paths->files . $target_page_id . '/' . 'puffy54.gif'; replace via API $file_target = $page->filesManager()->path; . 'puffy54.gif';
adrian Posted February 18, 2014 Posted February 18, 2014 I am sure I am missing something about what you want to do, but this works for me: $target_page = $pages->get(xxxx); $target_page->files->add("full url to file"); $target_page->of(false); $target_page->save(); I haven't looked to see what PW is using in the background (maybe file_get_content with a fallback to cURL), but there might be an issue with file_get_contents if you have allow_url_fopen off in your server config. 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now