Jump to content

When user tries to download .iso, tar.gz, or .deb from my website php is opening the file instead of downloading it


foxclone
Go to solution Solved by gizmola,

Recommended Posts

2 hours ago, foxclone said:

@gizmola - re: php directory - That is part of the structure provided by the web host.

I've searched all over the web trying to find a tutorial for building a config.php file without success. Lots of info on using php.ini but nothing specifically about config.php. Can you point me to something that will help me learn how to use it?

 

It's something you implement yourself.  It's a pattern, not a built in feature of php.  If you use the code I provided, making any necessary substitutions to fit your directory structure, you are on your way.

 

As for the structure provided by the webhost, can you have php scripts outside of the php directory?  If so, then it doesn't matter if they provided that directory or not.  If they force you to have all your php files inside that directory, then that is a pretty crappy hosting solution, but then again we see these all the time. 

 

The best practice these days for php development is to develop your project locally, using virtualization with vagrant/virtualbox or docker.  Along the way you use git to version control your sourcecode, pushing it to an external repository on github or bitbucket or gitlab.  You then deploy to the production server. 

I don't think that anyone should settle for a host that prohibits you from using whatever project structure your want, even for "free" hosting, but again, I don't know anything about your hosting situation.

Link to comment
Share on other sites

@gizmola - I moved all that was in the php directory into a newly created directory called includes. My config.php now looks like this:

<?php

$app_root = DIRNAME(__DIR__);

$php_path = $app_root.'../includes/';

include_once $php_path.'PDO_Connection_Select.php';

My index.php starts like this:

<?php

require('../includes/config.php');

require_once($php_path . 'PDO_Connection_Select.php');

require_once($php_path . 'GetUserIpAddr.php');

$ip = GetUserIpAddr();

if (!$pdo = PDOConnect("foxclone_data")) {

exit;

}

$stmt = $pdo->prepare("INSERT INTO access (address) values (?)");

$stmt->execute([$ip]) ;

?>

<?PHP require_once($php_path . 'header.php'); ?>

Problem is, I'm now getting the following error:

Quote

 

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

 

The error log states:

Quote

Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration, referer: http://foxtest/

Any idea what's going on?

Link to comment
Share on other sites

Foxtest:

Please start a new thread.  The error you posted has nothing to do with prior changes you made.  Most likely you have a .htaccess file, with some rewrite rules in it, and something is wrong with directives you have in your .htaccess file, or your server isn't even setup to support mod_rewrite, although more than likely it is, and there is some other issue with the format of your directives.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.