
foxclone
Members-
Posts
105 -
Joined
-
Last visited
About foxclone
- Birthday 09/19/1948
Profile Information
-
Gender
Male
-
Location
Coastal South Carolina
-
Interests
Web building, fishing rod building
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
foxclone's Achievements
-
Problem allowing users to download files from my website
foxclone replied to foxclone's topic in PHP Coding Help
I have everything working now, including updating the database, which is new code. Here's the code: <?php error_reporting(E_ALL); ini_set('display_errors', '1'); function mydloader($l_filename=NULL){ $file=basename($l_filename); $file=__DIR__.'/'.$file; if (file_exists($file)) { // Make database entry require '../../php/PDO_Connection_Select.php'; require '../../php/GetUserIpAddr.php'; $ip = GetUserIpAddr(); if (!$pdo = PDOConnect("foxclone_data")) { exit("unable to connect to database"); } $ext = pathinfo($l_filename, PATHINFO_EXTENSION); $test = $pdo->query("SELECT lookup.id FROM lookup WHERE inet_aton('$ip') >= lookup.ipstart AND inet_aton('$ip') <= lookup.ipend"); $ref = $test->fetchColumn(); $ref = intval($ref); $stmt = $pdo->prepare("INSERT INTO download (`address`, `filename`, `ip_address`, `lookup_id`) VALUES (?, ?, inet_aton('$ip'),?)"); $stmt->execute([$ip, $ext, $ref]) ; } if (!file_exists($file)) { exit("Requested file ($file) does not exist"); } else { header('Content-Description: File Transfer'); header('Content-Type: ' . mime_content_type($file)); header('Content-Disposition: inline; filename="'.basename($file).'"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); readfile($file); exit; } } mydloader($_GET["f"]); I had to put the database update before the file send otherwise the md5sum of the downloaded file was incorrect. Thanks to everyone for their input. I'm currently testing a change for the calling page to pass an integer instead of the filename and doing a lookup for the filename in this script. -
Problem allowing users to download files from my website
foxclone replied to foxclone's topic in PHP Coding Help
@gizmola - I've modified the code using many of the suggestions made in this thread. Here's the code that I have now: <?php error_reporting(E_ALL); ini_set('display_errors', '1'); $file=basename($_GET['f']); $file=__DIR__.'/download/'.$file; function mydloader($file) { if (!file_exists($file)) { die; } else { header('Content-Description: File Transfer'); header('Content-Type: ' . mime_content_type($file)); header('Content-Disposition: inline; filename="'.basename($file).'"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); readfile($file); exit; } } mydloader($_GET["f"]); I thank everyone for their input. -
Problem allowing users to download files from my website
foxclone replied to foxclone's topic in PHP Coding Help
@kicken Thanks for the suggestion. I'll implement it. -
Problem allowing users to download files from my website
foxclone replied to foxclone's topic in PHP Coding Help
@gizmola The filename is passed from a button click on the on the download page. Here's a sample: <a href="download/mydloader.php?f=<?php echo $debname;?>"><center><img src="images/us_download.png" style="height:35px; width:144px; margin-bottom:.5rem;" alt="download deb file"> </center></a> The mydloader.php is located in the folder with the files that are available to download. My intent with the die statement was intended as a failsafe in case the file_exists was false. -
Problem allowing users to download files from my website
foxclone replied to foxclone's topic in PHP Coding Help
It's a .deb file. VScode won't open it because it's binary. -
Problem allowing users to download files from my website
foxclone replied to foxclone's topic in PHP Coding Help
Never mind about web caching, my web host told me how to do it thru cpanel. -
Problem allowing users to download files from my website
foxclone replied to foxclone's topic in PHP Coding Help
What is the correct setting in php.ini to prevent server caching? -
Problem allowing users to download files from my website
foxclone replied to foxclone's topic in PHP Coding Help
@mac_gyver Contents of the partial file follow <br /> <b>Warning</b>: Undefined variable $file_url in <b>/home/foxclo98/public_html/mydloader.php</b> on line <b>21</b><br /> <br /> <b>Fatal error</b>: Uncaught ValueError: Path cannot be empty in /home/foxclo98/public_html/mydloader.php:21 Stack trace: #0 /home/foxclo98/public_html/mydloader.php(21): readfile('') #1 /home/foxclo98/public_html/mydloader.php(44): mydloader('foxclone50_amd6...') #2 {main} thrown in <b>/home/foxclo98/public_html/mydloader.php</b> on line <b>21</b><br /> -
Problem allowing users to download files from my website
foxclone replied to foxclone's topic in PHP Coding Help
@mac_gyver The downloaded file is only 495 bytes of a 5 meg .deb file. I'll check for an error file on my web host. -
I want to allow users on my hosted website to download files. Most of the following code was copied from php.net but when I run it, I'm only getting 495 bytes of a 5.7M file when testing downloads from my webhost. This code exists in a window that is never seen by the user. $l_filename is passed from another window. I'm not seeing any errors. My code follows: <?php error_reporting(E_ALL); ini_set('display_errors', '1'); function usdloader($l_filename=NULL){ if (file_exists($l_filename)) { $file = preg_replace("/\s+/u", " ", $l_filename); header('Content-Description: File Transfer'); header('Content-Type: ' . mime_content_type($file)); header('Content-Disposition: inline; filename="'.basename($file).'"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); readfile($file); else die; } } usdloader($_GET["f"]); I thank you for your help.
-
PHP Parse error: syntax error, unexpected '<'
foxclone replied to thesunlover's topic in PHP Coding Help
@thesunlover - There's a freshly released version of your system: Discuz! X3.4 official version [2022-04-06]. You can get it at https://www.discuz.net/. The source code is also available from that site. You can pass that information to whoever you hire, if you go that route. -
PHP Parse error: syntax error, unexpected '<'
foxclone replied to thesunlover's topic in PHP Coding Help
There's a freshly released version of your system: Discuz! X3.4 official version [2022-04-06]. I suggest you install it, it might help you. You can get it at https://www.discuz.net/. The source code is also available from that site. -
PHP Parse error: syntax error, unexpected '<'
foxclone replied to thesunlover's topic in PHP Coding Help
Is it possible that the host has removed PHP 7.4 and installed PHP 8 in anticipation of the upcoming EOL for 7.4? I'd confirm that PHP 7.4 is still available on your host. -
PHP Parse error: syntax error, unexpected '<'
foxclone replied to thesunlover's topic in PHP Coding Help
Using a 2006 templated program, in all likelyhood, will need more than just fixing this section to work with php7.x or php8.x. A lot has changed in the last 16 years. I suggest you find something a lot more recent. -
PHP Parse error: syntax error, unexpected '<'
foxclone replied to thesunlover's topic in PHP Coding Help
You're not closing each php section properly. <?=$bbname?'.'> is improperly closing php. Think about the how you close a php section of an html document.