cobusbo Posted December 30, 2015 Share Posted December 30, 2015 Hi im running a script to remove files from a directory but seems like I'm doing something wrong with the paths to the file First let me start with the field in my database. its stored as images/filename.jpg The fulle path to the file is chat2/profile/images/filename.jpg The file with the script im trying to run is in the chat2 folder I got the following stored in my script $pprofilepic = "../profile/".$rowbd['pprofilepic']; unlink($pprofilepic); but im getting the error Warning: unlink(../profile/images/resized_1198_1448338715.jpg): No such file or directory in /home/zhetnsdd/public_html/chat2/cron.php on line 16 Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted December 30, 2015 Share Posted December 30, 2015 it's a single . [dot] ./ = start in current directory ../ = start in parent directory Quote Link to comment Share on other sites More sharing options...
cobusbo Posted December 31, 2015 Author Share Posted December 31, 2015 it's a single . [dot] ./ = start in current directory ../ = start in parent directory Not helping <?php include("chat_code_header.php"); $querybd = "SELECT Username, last_online, pprofilepic FROM Users2 WHERE last_online < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 30 DAY))"; $resultbd = mysql_query($querybd) or die(mysql_error()); $users = array(); while($rowbd = mysql_fetch_array($resultbd)){ if ($rowbd['Username'] != '') $users[] = $rowbd['Username']; if($rowbd['pprofilepic'] == ""){}else{ $pprofilepic = "./profile/".$rowbd['pprofilepic']; print "\n Pictures Removed:\n" . $pprofilepic . "\n"; unlink($pprofilepic); } } $list = implode('; ', $users); if($list == ""){printf ("Nobody Removed\n");}else{ print "\n Users Removed:\n" . $list . "\n"; } printf("Users Deleted: %d\n", mysql_affected_rows()); $sqldel = "DELETE Users2, StringyChat, pm, namechanges, kicksamount, broadcast, timeban FROM Users2 LEFT JOIN StringyChat ON Users2.mxitid = StringyChat.StringyChat_ip LEFT JOIN pm ON Users2.mxitid = pm.mxitid LEFT JOIN namechanges ON Users2.mxitid = namechanges.userid LEFT JOIN kicksamount ON Users2.mxitid = kicksamount.mxitid LEFT JOIN broadcast ON Users2.mxitid = broadcast.mxitid LEFT JOIN timeban ON Users2.mxitid = timeban.mxitid WHERE Users2.last_online < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 30 DAY))"; mysql_query($sqldel) or die("Error: ".mysql_error()); $query = "DELETE FROM StringyChat WHERE StringyChat_time < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 7 DAY))"; mysql_query($query); printf("Messages deleted: %d\n", mysql_affected_rows()); $query1 = "DELETE FROM pm WHERE time < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 7 DAY))"; mysql_query($query1); printf("Private Messages deleted: %d\n", mysql_affected_rows()); ?> and output is as follow Pictures Removed: ./profile/images/resized_976_1447730821.jpg Warning: unlink(./profile/images/resized_976_1447730821.jpg): No such file or directory in /home/zhetnsdd/public_html/chat2/cron.php on line 16 Pictures Removed: ./profile/images/resized_1380_1448867798.jpg Warning: unlink(./profile/images/resized_1380_1448867798.jpg): No such file or directory in /home/zhetnsdd/public_html/chat2/cron.php on line 16 Users Removed: Ernest; The man; Mrs pelton; Quinton; Refresh; Don carter; Kevin; Orange; Edison; Max; Cagy LPD; Salie; knoxman; dcnator ; Melany; NOMFUNDO; Princess; me; Gummy bear; Back; Leilo; michael; Man x; Hot chick; Jason; Mpendulo Users Deleted: 26 Messages deleted: 290 Private Messages deleted: 140 Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted December 31, 2015 Share Posted December 31, 2015 do these images work correctly when your chat code displays them by retrieving the 'pprofilepic' value and producing an <img link? are you sure that the images exist and haven't already been removed? relative paths are relative to the current working directory. what does adding the the following to the script show - echo getcwd(); echo '<br>'; echo __FILE__; also, please browse to one of these images and post the URL for us to see. if you don't want to post your domain name, xxxx it out, but don't change anything that's after the domain name. you could always form an absolute path, starting with '/home/zhetnsdd/public_html/chat2/profile/' and concatenate the 'pprofilepic' value it. if you are going to run this script via a cron job (you are apparently browsing to it now), i'm not sure what the correct env variable would be to build that dynamically. Quote Link to comment Share on other sites More sharing options...
Barand Posted December 31, 2015 Share Posted December 31, 2015 You could also try using realpath() Quote Link to comment Share on other sites More sharing options...
cobusbo Posted December 31, 2015 Author Share Posted December 31, 2015 do these images work correctly when your chat code displays them by retrieving the 'pprofilepic' value and producing an <img link? are you sure that the images exist and haven't already been removed? relative paths are relative to the current working directory. what does adding the the following to the script show - echo getcwd(); echo '<br>'; echo __FILE__; also, please browse to one of these images and post the URL for us to see. if you don't want to post your domain name, xxxx it out, but don't change anything that's after the domain name. you could always form an absolute path, starting with '/home/zhetnsdd/public_html/chat2/profile/' and concatenate the 'pprofilepic' value it. if you are going to run this script via a cron job (you are apparently browsing to it now), i'm not sure what the correct env variable would be to build that dynamically. Yes I'm trying to run the script as a cron job every 24h http://xxxxxxxx/chat2/profile/images/resized_1380_1448867798.jpg Do I need to include the full path to unlink the file because in the previous I had a file in the profile folder which I just included the $rowbd['pprofilepic'] I will only be able to test the rest of the codes you gave me once there is a user to remove with an image Quote Link to comment 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.