Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Invalid file when opening any file for editing #2

Open
dsoini opened this issue Jul 8, 2013 · 18 comments · May be fixed by #5
Open

Error: Invalid file when opening any file for editing #2

dsoini opened this issue Jul 8, 2013 · 18 comments · May be fixed by #5

Comments

@dsoini
Copy link

dsoini commented Jul 8, 2013

It appears the basename() function does not provide the proper filename for the built-in pages that come with the Pico CMS (Welcome, Sub Page Index and Sub Page). This results in Invalid file errors when attempting to edit any of the pages. I am using wamp.

@chanchal1987
Copy link

I am also facing the same problem. I think there should one more option for the file location and file name in New and Edit options.

@ghost
Copy link

ghost commented Jul 17, 2013

Also experiencing this issue. I can edit files created by the editor, but when I try to edit pages created manually, I get "Error: Invalid file".

@pomaxa pomaxa linked a pull request Aug 27, 2013 that will close this issue
@ludwigmair
Copy link

can not open already existing pages correctly

Error: Invalid file

@ChristianGiupponi
Copy link

Same error

@w-vi
Copy link

w-vi commented Jan 9, 2014

Ideally look at some of the forks fixing it, there are couple of them floating around.
basename() leaves only the last trailing part of the path so the file is always looked up in the root directory.

@crempp
Copy link

crempp commented May 14, 2014

It looks like there are multiple causes for this error.

I'm looking into fixing them.

By the way, does any know if this project is maintained anymore? It doesn't seem like it. It's been 10 months since any activity, there are 8 pull requests waiting and no response to issues from the project owner. I'd be willing to take over, I'd probably have to fork and apply the pull requests manually.

@khanduras
Copy link

It would be nice to have a working editor for pico.

Edit: I have some specific requests after working with Pico over night. Some are obvious, others are special requests

  1. Be able to edit a different file name compared to its title
  2. Create, edit and move documents from one directory to another
  3. Always have the "Save" button handy
  4. Some sort of preview akin to this: http://www.getuikit.com/docs/addons_markdownarea.html
  5. Front-end editor instead of a backend one as the backend defeats the purpose of pico

That's all I can think up at this time, I'm sure others have other requests for this plugin as well.

@wesselgrift
Copy link

Is this fixed? Would be great to have this working.

@roryjarrard
Copy link

If anyone is looking at this thread any more, this fixes this problem. Edit pico_editor.php.

if(!isset($_SESSION['pico_logged_in']) || !$_SESSION['pico_logged_in']) die(json_encode(array('error' => 'Error: Unathorized')));
    $file_url = isset($_POST['file']) && $_POST['file'] ? $_POST['file'] : '';

    /*
     * This was rewritten from the GitHub, as basename() did not work
     */
    $parts = parse_url($file_url);
    $file = $parts['path']; // past the domain

    if(!$file) die('Error: Invalid file');

    // directories end in '/' and assume index, but that doesn't show in the POST value
    if(substr($file, -1) == '/') {
        $file .= 'index';
    }

    $file .= CONTENT_EXT;

    // remove the initial '/' from the requested page before prepending CONTENT_DIR
    $file = substr($file, 1);

    if(file_exists(CONTENT_DIR . $file)) die(file_get_contents(CONTENT_DIR . $file));
    else die('Error: Invalid file');

@wesselgrift
Copy link

Hi Rory,

I'm a bit of a PHP noob, where do I edit this in the file? :)

Thanks

@roryjarrard
Copy link

Sorry I should have mentioned that. This was the function do_open()

On Thu, Apr 2, 2015 at 9:56 AM, Wessel Grift [email protected]
wrote:

Hi Rory,

I'm a bit of a PHP noob, where do I edit this in the file? :)

Thanks


Reply to this email directly or view it on GitHub
#2 (comment)
.

@wesselgrift
Copy link

Thanks, but still getting Error: file invalid, unfortunately :*(
I used it like this:

    if(!isset($_SESSION['pico_logged_in']) || !$_SESSION['pico_logged_in']) die(json_encode(array('error' => 'Error: Unathorized')));
    $file_url = isset($_POST['file']) && $_POST['file'] ? $_POST['file'] : '';

    /*
     * This was rewritten from the GitHub, as basename() did not work
     */
    $parts = parse_url($file_url);
    $file = $parts['path']; // past the domain

    if(!$file) die('Error: Invalid file');

    // directories end in '/' and assume index, but that doesn't show in the POST value
    if(substr($file, -1) == '/') {
        $file .= 'index';
    }

    $file .= CONTENT_EXT;

    // remove the initial '/' from the requested page before prepending CONTENT_DIR
    $file = substr($file, 1);

    if(file_exists(CONTENT_DIR . $file)) die(file_get_contents(CONTENT_DIR . $file));
    else die('Error: Invalid file');

@roryjarrard
Copy link

The best thing you can do is debug, or if you don't have that capacity, then add some lines in there like:

$parts = parse_url($file_url);
die(var_dump($parts));

And before the final if statement
$file = substr($file, 1);
die($file);

Those messages will show up right in the editor area. Make sure to check them one at a time, because it will stop at the "die" statement, and the first one will keep you from seeing the second one.

@wesselgrift
Copy link

Alright, thanks:) I'll give it a try!

@wesselgrift
Copy link

Me and my collegue made a dirty fix:
$file = str_replace('pico/', '', $file);
now the basename works :)

somehow it did: localhost/pico/content/pico/index.md

@roryjarrard
Copy link

I"m glad that worked for you, but keep in mind that is specific to your
implementation. It's better to have an agnostic solution that doesn't
depend on a specific folder name or specific domain name (like "pico").

On Fri, Apr 3, 2015 at 12:20 PM, Wessel Grift [email protected]
wrote:

Me and my collegue made a dirty fix:

$file = str_replace('pico/', '', $file);

now the basename works :)


Reply to this email directly or view it on GitHub
#2 (comment)
.

@wesselgrift
Copy link

Indeed :) I hope someone will come along for a more permanent fix.

@tranduyhung
Copy link

This is my quick fix for this issue, replace your do_open, do_save and do_delete functions in plugins/pico_editor/pico_editor.php with this gist: https://gist.github.com/tranduyhung/09ad558cb0a53b5f6be2

Please try this code on a test site. Although it works for me but it could erase your content or delete your file if it has a bug hidden somewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants