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

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.