marksie1988 Posted January 3, 2008 Share Posted January 3, 2008 i have the following script <?php include("../../login/include/session.blc");//i assume this is your database connection? $user = (int)$_GET['user']; //type casting to ensure it is an integer $upload = urldecode($_GET['upload']); $query = "SELECT * FROM users WHERE username = $user"; $result = mysql_query ($query); while ($row = mysql_fetch_array($result)) { $pic = $row['pic']; unlink($pic); } $query = "UPDATE `users` SET `pic` = '' WHERE `username` = $user"; $result = mysql_query($query) or die(mysql_error()); header("location:$upload");//forward the user to the destination ?> when the user wants to change there picture they click a link which will run the above script, but what is happening is i get this error Warning: unlink() [function.unlink]: open_basedir restriction in effect. File() is not within the allowed path(s): (/home/marksie:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/****/public_html/****/login/userpics/delimg.blc on line 17 so i went and changed the while to an if and then added the full path to my script as follows <?php include("../../login/include/session.blc");//i assume this is your database connection? $user = (int)$_GET['user']; //type casting to ensure it is an integer $upload = urldecode($_GET['upload']); $query="select * from users"; // query string stored in a variable $rt=mysql_query($query); // query executed echo mysql_error(); if($nt=mysql_fetch_array($rt)){ $pic=$nt[pic]; // name class and mark will be printed with one line break at the end $dir = "/home/*****/public_html/****/login/userpics/"; $dest = $dir.$pic; unlink($dest); } $query = "UPDATE `users` SET `pic` = '' WHERE `username` = $user"; $result = mysql_query($query) or die(mysql_error()); header("location: ../".$upload);//forward the user to the destination ?> but then i get the following and if i echo the $pic it no longer works where as when it was a while statement it did work Warning: unlink(/home/****/public_html/****/login/userpics/) [function.unlink]: Is a directory in /home/marksie/public_html/blacklime/login/userpics/delimg.blc on line 17 please could someone help with this as i dont know where im going wrong Quote Link to comment https://forums.phpfreaks.com/topic/84373-solved-unlink-not-working-help-driving-me-crazy/ Share on other sites More sharing options...
papaface Posted January 3, 2008 Share Posted January 3, 2008 Can you show us an example of what $pic contains. Quote Link to comment https://forums.phpfreaks.com/topic/84373-solved-unlink-not-working-help-driving-me-crazy/#findComment-429742 Share on other sites More sharing options...
marksie1988 Posted January 3, 2008 Author Share Posted January 3, 2008 $pic simply contains a picture name which is the users name and then the file extension e.g. mine would be marksie1988.png Quote Link to comment https://forums.phpfreaks.com/topic/84373-solved-unlink-not-working-help-driving-me-crazy/#findComment-429780 Share on other sites More sharing options...
redarrow Posted January 3, 2008 Share Posted January 3, 2008 try that <?php if($nt=mysql_fetch_array($rt)){ $pic=$nt[pic]; // name class and mark will be printed with one line break at the end $dir = "/home/*****/public_html/****/login/userpics/"; $dest = $dir.$pic; @chmod($dest,0777); @unlink($dest); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84373-solved-unlink-not-working-help-driving-me-crazy/#findComment-429784 Share on other sites More sharing options...
duclet Posted January 3, 2008 Share Posted January 3, 2008 Try echoing the $dest before you unlink it to see if it is actually removing the correct file because from the error message, it seems like you are trying to remove a directory and not a file. Quote Link to comment https://forums.phpfreaks.com/topic/84373-solved-unlink-not-working-help-driving-me-crazy/#findComment-429785 Share on other sites More sharing options...
redarrow Posted January 3, 2008 Share Posted January 3, 2008 Try echoing the $dest before you unlink it to see if it is actually removing the correct file because from the error message, it seems like you are trying to remove a directory and not a file. what you talking about your going on about rmdir function no unlink edit was 0777 Quote Link to comment https://forums.phpfreaks.com/topic/84373-solved-unlink-not-working-help-driving-me-crazy/#findComment-429788 Share on other sites More sharing options...
marksie1988 Posted January 3, 2008 Author Share Posted January 3, 2008 try that <?php if($nt=mysql_fetch_array($rt)){ $pic=$nt[pic]; // name class and mark will be printed with one line break at the end $dir = "/home/*****/public_html/****/login/userpics/"; $dest = $dir.$pic; @chmod($dest,0777); @unlink($dest); } ?> when i use that code i get Warning: chmod() [function.chmod]: Operation not permitted in /home/*****/public_html/*****/login/userpics/delimg.blc on line 16 Warning: unlink(/home/*****/public_html/*****/login/userpics/) [function.unlink]: Is a directory in /home/*****/public_html/*****/login/userpics/delimg.blc on line 17 also if i echo $dest it doesnt add the image just the directory :S EDIT: Also if i change the if statement to while then the $pic will echo but the $dir will loop Quote Link to comment https://forums.phpfreaks.com/topic/84373-solved-unlink-not-working-help-driving-me-crazy/#findComment-429790 Share on other sites More sharing options...
duclet Posted January 3, 2008 Share Posted January 3, 2008 Try echoing the $dest before you unlink it to see if it is actually removing the correct file because from the error message, it seems like you are trying to remove a directory and not a file. what you talking about your going on about rmdir function no unlink edit was 0777 I think you need to re-read what I posted. Anyway, as I have expected, the $pic is not being appended to the $dir when you form your $dest. Make sure that you are actually getting the expected value for $pic, then for $dest. Quote Link to comment https://forums.phpfreaks.com/topic/84373-solved-unlink-not-working-help-driving-me-crazy/#findComment-429791 Share on other sites More sharing options...
duclet Posted January 3, 2008 Share Posted January 3, 2008 Another thing, change mysql_fetch_array to mysql_fetch_assoc Quote Link to comment https://forums.phpfreaks.com/topic/84373-solved-unlink-not-working-help-driving-me-crazy/#findComment-429792 Share on other sites More sharing options...
marksie1988 Posted January 3, 2008 Author Share Posted January 3, 2008 i9 have changed that to assoc but doesnt change a thing i have echoed $pic and nothing is shown but as i said before if i change the if statement to a while then the $pic works but $dir loops Quote Link to comment https://forums.phpfreaks.com/topic/84373-solved-unlink-not-working-help-driving-me-crazy/#findComment-429794 Share on other sites More sharing options...
duclet Posted January 3, 2008 Share Posted January 3, 2008 Can you do a print_r on $nt and post what it returns here? Quote Link to comment https://forums.phpfreaks.com/topic/84373-solved-unlink-not-working-help-driving-me-crazy/#findComment-429795 Share on other sites More sharing options...
redarrow Posted January 3, 2008 Share Posted January 3, 2008 what is seesion.blc please........... if there asny session's invoved your need to use the unset() function Quote Link to comment https://forums.phpfreaks.com/topic/84373-solved-unlink-not-working-help-driving-me-crazy/#findComment-429805 Share on other sites More sharing options...
redarrow Posted January 3, 2008 Share Posted January 3, 2008 try that mate <?php session_start(); if($nt=mysql_fetch_assoc($rt)){ $_SESSION['pd']=$nt['pic']; } // name class and mark will be printed with one line break at the end $dir = "/home/*****/public_html/****/login/userpics/"; $dest = $dir.$_SESSION['pd']; @chmod($dest,0777); @unlink($dest); ?> Quote Link to comment https://forums.phpfreaks.com/topic/84373-solved-unlink-not-working-help-driving-me-crazy/#findComment-429809 Share on other sites More sharing options...
marksie1988 Posted January 4, 2008 Author Share Posted January 4, 2008 no sessions are involved ok i have now managed to get it all working after using the print_r for some reason the $user was getting the wrong username so i changed that and it now works but i now get an error for the chmod Warning: chmod() [function.chmod]: Operation not permitted in /home/*****/public_html/*****/login/userpics/delimg.blc on line 19 would i need to use chown? Quote Link to comment https://forums.phpfreaks.com/topic/84373-solved-unlink-not-working-help-driving-me-crazy/#findComment-429816 Share on other sites More sharing options...
redarrow Posted January 4, 2008 Share Posted January 4, 2008 no delete it and post current working code and press solved Quote Link to comment https://forums.phpfreaks.com/topic/84373-solved-unlink-not-working-help-driving-me-crazy/#findComment-429822 Share on other sites More sharing options...
marksie1988 Posted January 4, 2008 Author Share Posted January 4, 2008 if($nt=mysql_fetch_assoc($rt)){ $pic=$nt[pic]; // name class and mark will be printed with one line break at the end $dir = "/home/******/public_html/****/login/userpics/"; $dest = $dir.$pic; unlink($dest); } Quote Link to comment https://forums.phpfreaks.com/topic/84373-solved-unlink-not-working-help-driving-me-crazy/#findComment-429825 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.