Jump to content

Recommended Posts

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"); 
}

 

Link to comment
https://forums.phpfreaks.com/topic/51064-file-location-problem/
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.