Jump to content

Run independent PHP files within Processwire


nuel
 Share

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?

Link to comment
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
Link to comment
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.

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...