write permissions
Posted: Sat Jun 12, 2010 12:11 pm
Hi,
At my site I host applications for Mac OS X. Now I was wondering how many people clicked my download link. So I started with a test page. Just 3 files (loga, logb & logc) in a folder and a PHP file which would read the file or increase the number of the file. The HTML contained three links for viewing the log files and three links for increasing there count. Viewing the log count doesn't give me any problems, but, as I already was expecting, increasing the count does
This is my PHP file which shows or (tries to) increase the count contained by the file.
Here I have hosted the test project
I hope somebody can help me,
ief2
At my site I host applications for Mac OS X. Now I was wondering how many people clicked my download link. So I started with a test page. Just 3 files (loga, logb & logc) in a folder and a PHP file which would read the file or increase the number of the file. The HTML contained three links for viewing the log files and three links for increasing there count. Viewing the log count doesn't give me any problems, but, as I already was expecting, increasing the count does
This is my PHP file which shows or (tries to) increase the count contained by the file.
Code: Select all
function getLogCount($logName) {
$fullFileName = "txts/" . $logName . ".txt";
// read log
$fileSize = filesize($fullFileName);
if($fileSize <= 0) {
return 0;
}
$openedFile = fopen($fullFileName, "r");
$count = fread($openedFile, filesize($fullFileName));
fclose($openedFile);
$count = (integer)$count;
return $count;
}
function increaseLogCount($logName) {
$fullFileName = "txts/" . $logName . ".txt";
// read log
$count = getLogCount($logName);
$newCount = (integer)$count + 1;
$openedFile = fopen($fullFileName, "w");
$success = fwrite($newCountn, $openedFile);
fclose($openedFile);
echo "Writing Succes? " . $success;
}
// MAIN
$type = $_GET['type'];
$logname = $_GET['logname'];
echo "TYPE: " . $type . "<br /><br />";
if($type == "print") {
$count = getLogCount($logname);
echo "Count in " . $logname . ": " . $count;
} elseif($type == "increase") {
increaseLogCount($logname);
} else {
echo "Unknown Command";
}Here I have hosted the test project
I hope somebody can help me,
ief2