Jump to content

Recommended Posts

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 


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

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

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

 

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.

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

?>

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?

 

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

}

 

 

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.