I’m currently writing a script, So i can upload a picture and it will add some info to a .htacces file and also it will create a .txt file. The thing is I’m runing the script from /digg/stats and the .htaccess is in /digg/ and so will the picture, but I can’t seem to get the .htaccess and picture to be written/put from digg/stats to just /digg. Below is my script:
<?php
//Getting & Creating/ Text file
$file = preg_replace ('/[^a-zA-Z0-9\_ ]/', '', $_POST['textfile']);
$file = str_replace(' ', '_', $file);
$image_name = $file;
$file = $file.".txt";
if (file_exists($file)) {
die ("The Link/Image Name You Have Entered Already Exists");
}
if($_FILES['imagefile']['type'] == "image/jpeg") {
$type = ".jpg";
} else if ($_FILES['imagefile']['type'] == "image/gif") {
$type = ".gif";
} else if ($_FILES['imagefile']['type'] == "image/png") {
$type = ".png";
} else {
die("Invalid Image Type");
}
$f = fopen ($file, 'w');
fputs ($f, "");
fclose ($f);
//Uploading File
$uploadpath = 'digg/';
$new_name = $uploadpath.$image_name.$type;
copy ($_FILES['imagefile']['tmp_name'], $new_name)
or die ("Could not copy");
//Write to .htaccess
$htaccess = '.htaccess';
$slash = "\\";
$content = "
RewriteRule ^$image_name$ image_tracker.php?image=$image_name$slash$type
RewriteRule ^$image_name/$ image_tracker.php?image=$image_name$type
RewriteRule ^$image_name$slash$type$ image_tracker.php?image=$image_name$slash$type";
//Checks / creates file
if (!$handle = fopen($htaccess, 'a+')) {
echo "Cannot open file ($htaccess)";
exit;
}
//Write To File
if (fwrite($handle, $content) === FALSE) {
echo "Cannot write to file ($htaccess)";
exit;
}
fclose($handle);
if (!is_writable('.htaccess')) {
die("The file $htaccess is not writable");
}