php - Deleting files in higher directory -
i'm having problems deleting file higher directory, found post , tried no luck....:
gotdalife @ gmail dot com 25-sep-2008 02:04
to who's had problem permissions denied error, it's caused when try delete file that's in folder higher in hierarchy working directory (i.e. when trying delete path starts "../").
so work around problem, can use chdir() change working directory folder file want unlink located.
<?php > $old = getcwd(); // save current directory > chdir($path_to_file); > unlink($filename); > chdir($old); // restore old working directory ?>
here code have:
session_start(); if (!isset($_session['agent']) or ($_session['agent'] !=md5($_server['http_user_agent']))){ require_once ('includes/login_functions.inc.php'); $url = absolute_url(); header("location: $url"); exit(); } $folder = $_get['folder']; $filename = $_get['name']; $path = "../gallery/photos/$folder"; if (isset($_post['submitted'])) { if ($_post['sure'] == 'yes') { $old = getcwd(); // save current directory chdir($path); unlink($filename); chdir($old); // restore old working directory } else{ echo '<p>the photo has not been deleted.</p>'; } }
i'm getting error message :
warning: unlink() [function.unlink]: no error in j:\xampp\htdocs\bunker\admin\delete_file.php on line 37
line 37 being:
unlink($filename);
can see i've done wrong?
i use absolute filepath names.
i'd define filedir constant in config, concatenate have absolute filepath, make call unlink().
btw: hope know code highly insecure.
Comments
Post a Comment