seb hughes Posted May 12, 2007 Share Posted May 12, 2007 I'm creating a script that will upload a file,create a txt file and add data to a .htaccess file. The problem im having is that the script runs from digg/stats and the .htaccess is in /digg/ aswell as the picture upload place, but I cant seem to run the script from digg/stats and get the .htaccess updated in /digg/ nor will the picture upload to that place, below is my code: <?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 = "\r\nRewriteRule ^$image_name$ image_tracker.php?image=$image_name$slash$type\r\nRewriteRule ^$image_name/$ image_tracker.php?image=$image_name$type\r\nRewriteRule ^$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"); } Quote Link to comment https://forums.phpfreaks.com/topic/51064-file-location-problem/ Share on other sites More sharing options...
MadTechie Posted May 12, 2007 Share Posted May 12, 2007 try $uploadpath = '../digg/'; or $uploadpath = '../'; Quote Link to comment https://forums.phpfreaks.com/topic/51064-file-location-problem/#findComment-251323 Share on other sites More sharing options...
seb hughes Posted May 12, 2007 Author Share Posted May 12, 2007 It worked for the image, but how would I do it for the .htaccess file that I am trying to write too. Thanks, Seb Hughes Quote Link to comment https://forums.phpfreaks.com/topic/51064-file-location-problem/#findComment-251343 Share on other sites More sharing options...
chigley Posted May 12, 2007 Share Posted May 12, 2007 <?php //Write to .htaccess $htaccess = '../.htaccess'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/51064-file-location-problem/#findComment-251344 Share on other sites More sharing options...
MadTechie Posted May 12, 2007 Share Posted May 12, 2007 if you want the same folder as the image folder then i would say use the below $htaccess = $uploadpath.".htaccess"; so you only have to remember to update one path Quote Link to comment https://forums.phpfreaks.com/topic/51064-file-location-problem/#findComment-251349 Share on other sites More sharing options...
seb hughes Posted May 12, 2007 Author Share Posted May 12, 2007 I now get this error: The file ../.htaccess is not writable But the thing is the script does every it should and it nows works, but i don't know why I'm getting this error, where there is no error. Quote Link to comment https://forums.phpfreaks.com/topic/51064-file-location-problem/#findComment-251365 Share on other sites More sharing options...
chigley Posted May 12, 2007 Share Posted May 12, 2007 Try CHMODing the .htaccess file to change it's permissions. Quote Link to comment https://forums.phpfreaks.com/topic/51064-file-location-problem/#findComment-251366 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.