Jump to content
nuel

Run independent PHP files within Processwire

Recommended Posts

Hi there

Basically I want to call code within a ProcessWire page that isn't used as a template. Example: www.mypwpage.com/myphpfile.php

I have a working PW Website with a couple of pages like /artists, /releases, /videos etc. Now I need a page /download without any editable fields in the backend, just calling some PHP code (that was coded by another guy) containing a form that checks unique download-codes in a second database and starts the download of the desired file. The script is working fine right now as part of a static website, but since I built PW behind the site, this independent «Download Section» of the page doesn't work anymore.

Right now I have the main file download.php as a page template on a newly created empty page called /download, so until now the form is working (wow). After sending the form containing the download-code, the file check_code.php in a subfolder /site/templates/download is called and that's where I get an error.

Any help?

Share this post


Link to post
Share on other sites
1 hour ago, nuel said:

I get an error

and what does it say? Most probably, you just have to adjust a path/URL. Or maybe you have to create a dummy PW template + page for check_code.php file as well.

  • Like 1

Share this post


Link to post
Share on other sites
9 minutes ago, dragan said:

Or maybe you have to create a dummy PW template + page for check_code.php file as well.

That, definitely. ProcessWire blocks access to all php files under site/templates.

Share this post


Link to post
Share on other sites

Hi,

Are you on ProcessWire 3 ? If yes then write at the top of the check_code.php the following code

<?php namespace ProcessWire;

 

52 minutes ago, nuel said:

the file check_code.php in a subfolder /site/templates/download is called and that's where I get an error.

What's the error(s) ?

-

Assuming the problem is calling this file, modify your call(s) to this file like that :

<!-- example for form action -->
<form method="post" action="<?= $config->urls->templates; ?>download/check_code.php">
  [...]
</form>

<!-- example for redirect -->
<?php $session->redirect($config->urls->templates . 'download/check_code.php');

 

  • Like 1

Share this post


Link to post
Share on other sites

Wow, thank you guys! Great inputs. I will try all that. For now I built the whole download page on a subdomain where i forward to in the /download template i forward with $session->redirect($url). It works, but it's not the beautiful solution I was hoping for (dynamic menu etc. is not affecting the subdomain etc.). I will post my solution here when I succeed.

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Mithlesh
      Changing it to null
    • By Mithlesh
      Hi, I have one URL - writerrelocations.com/contact-now/

      I have one issue where my header Image is appearing again after the contact form, for your reference:



      I have checked my processwire template section where have not added any Image field besides Header Image, attaching the same for the reference:




      PLEASE help me to get rid of the image below contact form

      Waiting for the swift response!

      Thanks
       
    • By DooM
      Hello guys,
      I'm trying to figure out how to sync fields and templates between staging and production environments.
      I've found Migrations module by Lostkobrakai, but with use of it all the fields and templates must be created by API, which is kind of uncomfortable.
      I also tried ProcessDatabaseBackups module which can export only certain tables, but I don't think it's the best practice to do that.
      How do you guys solve this problem? It's very annoying to setup everything three times (dev, staging, production).
      Thanks a lot :)
    • By iipa
      Hi fellow developers!
      I want to implement following action:
      Admin-priviledged user uploads a spreadsheet file (with many sheets) When page is saved, back end generates repeater items from the sheets We can render spreadsheet data from the repeater field. Profit! Currently I'm trying to find a way to read the uploaded spreadsheet file. ProcessWire doesn't seem to have modules suitable for my needs, but external PHP Library PhpSpreadsheet sounds like it could do the job. However, I can't even try it, because I simply don't understand how I can refer to an external library!
      Folder structure:
      templates _func.php > where I want to refer to the library libraries PhpSpreadsheet bunch of *.php > what I want to refer to I have tried different things varying from their documentation to forum posts and PW API with no luck. I would prefer not to use Composer, since it seems kind of overkill for one library.
      Thanks in advance and have a great day!
×
×
  • Create New...