Jump to content

Php download counter issue


Javil

Recommended Posts

Hi all,

 

i have trouble with a piece of code.

 

HTML:

 

<div class="psdBox"><a href="downloads/001_PSD.php"><img src="webBuild/psdIcon.png" alt="psd icon" /></a> 
   <div class="phpBox">
   <?php

$hit_count = @file_get_contents('http://example.com/downloads/001_PSD.txt');
echo $hit_count;
?></div></div>

 

PHP:

<?php

$url = 'http://example.com/downloads/001_PSD.txt';

$hit_count = @file_get_contents($url);
$hit_count++;
@file_put_contents($url);

header ('Location: http://example.com/downloads/001_PSD.zip'); 

?>

 

What i'm trying to do is to count the downloads on my site using PHP without sql.

 

This code working from the root. [www.example.com/here]

But if i want this code work from a folder [www.example.com/downloads/here]

then i does not work. The 001_PSD.txt won't count up from a folder.

 

In the root, where it works, the chmod of the 001_PSD.txt is standard 0644. This works!

I always thought that i must be 0777, but from the root 0644 is ok.

 

When i tested it from /downloads folder, i tried to set 001_PSD.txt to chmod 0777, but that also fails..

 

Can someone help me to make this work.. i cannot find the problem,

i want to make multiple downloads and don't want to put every download in the root folder..

 

thank,

 

javil

Link to comment
https://forums.phpfreaks.com/topic/224748-php-download-counter-issue/
Share on other sites

Yes.

 

Example.com\mypage.php.

In mypage.php stands this code:

 

<div class="psdBox"><a href="downloads/001_PSD.php"><img src="webBuild/psdIcon.png" alt="psd icon" /></a>
   <div class="phpBox">
   <?php

   $hit_count = @file_get_contents('http://example.com/downloads/001_PSD.txt');
   echo $hit_count;
   ?></div></div>

 

So yes, the .txt .zip and .php stands in the folder.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.