Jump to content

Jim Bailie

Members
  • Posts

    66
  • Joined

  • Last visited

Posts posted by Jim Bailie

  1. FWIW -- I have a template called "downloads".

    When someone goes to https://example.com/downloads/specialfilename.php, the file name is treated as a url segment. From the url segment, I will essentially:

    • Search for the file
    • Make sure it's there
    • Then deliver it via the mime process
    // Get page ($p) where the file lives
    
    // Still here, so lets see if we can get the actual file
    $file = $p->filesManager->getFile($fileNameSanitized);
    if(!$file) return 'File not found(3)';
    
    header("Content-Type: application/pdf");
    header("Content-Disposition: inline; filename=$fileName");
    header("Content-Transfer-Encoding: binary");
    header("Accept-Ranges: bytes");
    @readfile($file->filename);
    return true;

     

    • Like 1
  2. Thanks. Ok, this is a closed application and there's a 404 redirect in config.php set to go to a page/template with active access control.

    Therefore if I add a url segment to a protected page/template, it will get 404 redirected to a page/template that should redirect to a login page if there is no active session, but that protected page is rendered instead.

    I hope this makes sense. It's not the end of the world as I will need to do some checking in the code, but it is unexpected behavior.

  3. @elabx Thanks, yes. On other pages, I believe this is now interfering with a SAML check/authentication process as well.

     

    $config->prependTemplateFile = '_init.php';
    
    /**
     * Append template file
     *
     * PHP file in /site/templates/ that will be loaded after each page's template file.
     * Example: _main.php
     *
     * @var string
     *
     */
    $config->useMarkupRegions = true;
    $config->appendTemplateFile = '_main.php';

     

  4. Hello - My _init.php file is running twice and it's become urgent.

    The screenshot below is on the home page of a simple echo 'In Init'. There is nothing fancy going on on the home page that could lead to any path of inquiry. (See thread below AND the github issue referenced therein)

    Therefore, this is leading me to thing that it has something to do with regions perhaps.

    // _main.php
    <div id="main-content">
      <footer>Footer content</footer>
    </div>
    
    // template: home.php
    <div pw-prepend="main-content" class="min-h-full flex flex-col justify-center items-center bg-gray-200">
      Some content
    </div>

    screen-shot-ininit.jpg

  5. @Robin S When a file is replaced, I need to capture the date of the replacement and put in a page field.

    I'm not anywhere near your skill level, but starting to get comfortable with the basics all thanks to many of your recent posts and replies.

    Could you offer some guidance on how I might pursue this either with your module's code or some sort of hook arrangement? Thanks again!

  6. @da² Thanks, but the problem is that these full links need to be preserved because they're widely published inside this organization and among their clients and customers sales materials, so they have to be the same.

    I was hoping to have PW "fully" manage the files because it would be such a relief to the admins and would allow the org to track the viewership to a certain extent.

    I thought some of the information in this article would help, https://processwire.com/blog/posts/page-name-charset-utf8/ , but I just don't think PW is going to have anything to do with having a "$" anywhere near a url. 🤷‍♂️

  7. Taking inspiration from @Robin S's recent tutorial, I told a client we could map all their old pdf file names/links to their newly migrated, and sanitized files in PW. No problem, right?

    Last night I set up the URL hook "/concepts/{filename}", and /concepts/My_Test_File4$$$.pdf doesn't even fire the hook and throws a 404.

    So I disabled the hook, created the page "concepts" with a template that allows all url segments. "/concepts/My_Test_File4$$$.pdf" throws a 404.

    I've read EVERYTHING google/forum will give me pertaining to URL hooks and special chars in page names and such.

    Just looking for one more trick before I have to go native and just duplicate all the migrated files in their original directory structure. Thanks!!

  8. Update: Somehow by looking at Pagefile.php I was able to figure out how to set the uploadName via the API. It seems to work...

    $path = "/var/www/dvmrebuild/storage/";
    $fileName = "My_Test_File4$$$.pdf";
    $p = $pages->get(1214);
    
    $p->of(false);
    $p->venue_files->add($path . $fileName);
    $p->save('venue_files');
    
    $p->of(false);
    $vfile = $p->venue_files->last();
    $vfile->file_upload_date = date('Y-m-d');
    $vfile->file_title = 'My Test File 4'; 
    $vfile->file_original_name = $fileName;
    $vfile->filedata('uploadName', htmlentities($fileName));
    $p->save('venue_files');

     

  9. @bernhard Thanks for doing that. I'll dig up my github info and give a thumbs up.

    In the meantime, I'll try to cobble something together with some file template fields and some of @Robin S's examples above and in another post.

    I also wonder if the fact that the API does not preserve the uploadName cascades down to the fact that the uploadName is not set in Robin's file rename/replace module.

  10. 8 hours ago, bernhard said:

    How did you upload the file via api? Can you give a quick example to reproduce the issue?

    If you do that and post it to this issue and mention Ryan I guess chances are high that he will fix this quickly. At least I suggested the uploadName feature on Feb 16 and he implemented it on Feb 17 😄 

    Maybe he just didn't think of API uploads.

    @bernhard Here's the test code. Pretty simple; it uploads the file fine with the sanitized file name. When I loop through after, it outputs the file name and upload name which are the same.

    $path = "/var/www/dvmrebuild/storage/";
    $fileName = "My_Test_File3$$$.pdf";
    
    $p = $pages->get(1214);
    
    $p->of(false);
    $p->venue_files->add($path . $fileName);
    $p->save('venue_files');
    
    foreach ($p->venue_files AS $vfile) {
        echo $vfile->name . ' => ' . html_entity_decode($vfile->uploadName) . '<br>';
    }
    
    # Outputs:
    # my_test_file3.pdf => my_test_file3.pdf

     

  11. Hmm. Wow. This is great! I've got some work to do this weekend.

    I'll be testing this asap, but I will ask you in advance: Do you think the replace/rename module will preserve the upload name after replacement?

    Edit

    BTW, PW 3.0.226 - I'm not seeing the uploadName in the tooltip. The upload name was "conservation_station_tester2$$$.pdf" (see below)

    Good News -- I AM seeing upload names when looping via the API for files that have been manually uploaded

    Bad News  -- Rename/Replace module DOES REMOVE the original upload name and replaces with the sanitized version.

    Bad News  -- Uploading a file via the API places the SANITIZED value into uploadName

    I'd be grateful for any more insights or ideas you may have on how to proceed. Thanks again!!

    screen-shot-20230909.jpg

  12. 6 hours ago, Robin S said:

    Could you give more details about what you mean by this? Are you trying to import files via the API and this fails somehow? Or you mean that the $ character is not retained in the filename after you add the file to a Files field?

    We are transferring via API and it works fine. It's just that when event_concept_test$$$.pdf is loaded via api or manually, it DOES NOT retain the $'s

    And your tutorial is wonderful, but I really worry about confusion among the admins. If I understand correctly they won't see the non-sanitized file name and could lose track of which file is which if they check their work in the front-end.

×
×
  • Create New...