jomagi Posted February 11, 2009 Share Posted February 11, 2009 I made a php/mysql page with the command UNLINK to delete files, it works fine in the PC, but when I put files in SERVER it don't work. Any guess??? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/144748-unlink/ Share on other sites More sharing options...
FD_F Posted February 11, 2009 Share Posted February 11, 2009 check for permissions Quote Link to comment https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759538 Share on other sites More sharing options...
JonnoTheDev Posted February 11, 2009 Share Posted February 11, 2009 And filepaths Quote Link to comment https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759555 Share on other sites More sharing options...
jomagi Posted February 11, 2009 Author Share Posted February 11, 2009 Permissions think is allright, I can upload files with no problem. Paths, Ive tried change several times and no result, nothing work. Quote Link to comment https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759564 Share on other sites More sharing options...
andy_b42 Posted February 11, 2009 Share Posted February 11, 2009 Permissions think is allright, I can upload files with no problem. Paths, Ive tried change several times and no result, nothing work. Having access rights to create files doesn't neccesarily mean you will be able to delete them. Quote Link to comment https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759565 Share on other sites More sharing options...
jomagi Posted February 11, 2009 Author Share Posted February 11, 2009 Permissions are 777, I've check again! Quote Link to comment https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759572 Share on other sites More sharing options...
andy_b42 Posted February 11, 2009 Share Posted February 11, 2009 Only other thing i can think of then if you have 777 permissions on that folder and file would be that the directory is correct. Have you tried using getcwd() to check you are in the right place? Quote Link to comment https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759575 Share on other sites More sharing options...
JonnoTheDev Posted February 11, 2009 Share Posted February 11, 2009 Do you get an error from the unlink() function? Maybe you could use a file_exists() call first $file = '/var/www/html/docs/x.txt'; if(file_exists($file)) { unlink($file); } else { print "file not found: ".$file; } Quote Link to comment https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759578 Share on other sites More sharing options...
jomagi Posted February 11, 2009 Author Share Posted February 11, 2009 I add the file_exists and give no error, delete from mysql like allways but dont delete file from server. Quote Link to comment https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759580 Share on other sites More sharing options...
jomagi Posted February 11, 2009 Author Share Posted February 11, 2009 I made a echo at the variable and give nothing if ((isset($_GET['id'])) && ($_GET['id'] != "")) { $query = sprintf("SELECT * FROM etiquetas WHERE id=%s", GetSQLValueString($_GET['id'], "int")); $result = mysql_query($query); $row = mysql_fetch_array($result); $logoname = $row["logotipo"]; echo "nome ficheiro é:" . $logoname; Connection to database is ok because the record is deleted in the next step. Quote Link to comment https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759591 Share on other sites More sharing options...
redarrow Posted February 11, 2009 Share Posted February 11, 2009 add or die mysql_error() and also echo the query out to see if it correct. also in the query what the s <<< for, sprintf s is a string and i am sure you mean d decimal. Quote Link to comment https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759595 Share on other sites More sharing options...
redarrow Posted February 11, 2009 Share Posted February 11, 2009 my version. (re edited sorry. <?php if ((isset($_GET['id'])) && ($_GET['id'] != "")) { $query = sprintf("SELECT * FROM etiquetas WHERE id=%d", GetSQLValueString($_GET['id'], "int")); $result = mysql_query($query); while($row = mysql_fetch_array($result)){ $logoname = $row["logotipo"]; $logoname=$_POST['logonname']; } echo "nome ficheiro é:" . $logoname; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759598 Share on other sites More sharing options...
redarrow Posted February 11, 2009 Share Posted February 11, 2009 even better. re edited( added error cheeking. <?php if ((isset($_GET['id'])) && ($_GET['id'] != "")) { $query = sprintf("SELECT * FROM etiquetas WHERE id=%d", GetSQLValueString($_GET['id'], "int")); $result = mysql_query($query)or die (mysql_error()); if(mysql_num_rows($result)){ while($row = mysql_fetch_array($result)){ $logoname = $row["logotipo"]; $logoname=$_POST['logoname']; } } else { echo $query; exit; } echo "nome ficheiro é:" . $logoname; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759601 Share on other sites More sharing options...
redarrow Posted February 11, 2009 Share Posted February 11, 2009 very secure example for you. <?php if ((isset($_GET['id'])) && ($_GET['id'] != "")) { if(preg_match("/^[0-9]$/",$_GET['id'])){ $query = sprintf("SELECT * FROM etiquetas WHERE id=%d", GetSQLValueString($_GET['id'], "int")); $result = mysql_query($query)or die ("Select error mate <br>". mysql_error()); if(mysql_num_rows($result)){ while($row = mysql_fetch_array($result)){ $logoname = $row["logotipo"]; $logoname=$_POST['logoname']; } } else { echo $query; exit; } echo "nome ficheiro é:" . $logoname; }else{ echo " sorry this id {$_GET['id']} is not a number!"; exit; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759605 Share on other sites More sharing options...
jomagi Posted February 11, 2009 Author Share Posted February 11, 2009 Thanks for the help. I change the code and now return "sorry this id 25 is not a number!" Quote Link to comment https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759608 Share on other sites More sharing options...
redarrow Posted February 11, 2009 Share Posted February 11, 2009 try now mate tell me what happens. settype($_GET['id'],"integer"); <?php if ((isset($_GET['id'])) && ($_GET['id'] != "")) { settype($_GET['id'],"integer"); if(preg_match("/^[0-9]$/",$_GET['id'])){ $query = sprintf("SELECT * FROM etiquetas WHERE id=%d", GetSQLValueString($_GET['id'], "int")); $result = mysql_query($query)or die ("Select error mate <br>". mysql_error()); if(mysql_num_rows($result)){ while($row = mysql_fetch_array($result)){ $logoname = $row["logotipo"]; $logoname=$_POST['logoname']; } } else { echo $query; exit; } echo "nome ficheiro é:" . $logoname; }else{ echo " sorry this id {$_GET['id']} is not a number!"; exit; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759631 Share on other sites More sharing options...
jomagi Posted February 11, 2009 Author Share Posted February 11, 2009 Same result: "sorry this id 25 is not a number!" Quote Link to comment https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759689 Share on other sites More sharing options...
premiso Posted February 11, 2009 Share Posted February 11, 2009 Alright, jo. Post the code where you unlink the file. I fail to see any code like that up there. Better yet, post your full working code for us and I will see if we cannot get this solved for you. Quote Link to comment https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759700 Share on other sites More sharing options...
jomagi Posted February 11, 2009 Author Share Posted February 11, 2009 This is the code that work fine in PC with MYSQL on SERVER. <?php require_once('Connections/dargil_site.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } if ((isset($_GET['id'])) && ($_GET['id'] != "")) { $query = sprintf("SELECT * FROM etiquetas WHERE id=%s", GetSQLValueString($_GET['id'], "int")); $result = mysql_query($query); $row = mysql_fetch_array($result); $logoname = $row["logotipo"]; unlink($logoname); $deleteSQL = sprintf("DELETE FROM etiquetas WHERE id=%s", GetSQLValueString($_GET['id'], "int")); mysql_select_db($database_dargil_site, $dargil_site); $Result1 = mysql_query($deleteSQL, $dargil_site) or die(mysql_error()); $deleteGoTo = "admin_etiquetas.php"; if (isset($_SERVER['QUERY_STRING'])) { $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?"; $deleteGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $deleteGoTo)); } ?> Then I upload all files with filezilla to the SERVER and all works fine less the scripts with UNLINK. Thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759709 Share on other sites More sharing options...
premiso Posted February 11, 2009 Share Posted February 11, 2009 Ok, is there an error coming out, or is it just not deleting the file? If an error, post it here. $logoname = $row["logotipo"]; if (file_exists($logoname)) { $fileinfo = substr(sprintf('%o', fileperms($logoname)), -4); echo 'The permissions for the file ' . $logonname . ' are: ' . $fileinfo . '<br />'; if (unlink($logoname)) { echo 'The file ' . $logoname . ' should be erased.<br />'; }else { echo 'The file ' . $logoname . ' was not erased.<br />'; } }else { echo 'The file does not exist!'; } Add the above in there and run the script and report back what it outputs. Quote Link to comment https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759712 Share on other sites More sharing options...
jomagi Posted February 11, 2009 Author Share Posted February 11, 2009 No error displayed! All go well, just the file isn't deleted, when I go check folder, the files remain there in the server. Quote Link to comment https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759758 Share on other sites More sharing options...
premiso Posted February 11, 2009 Share Posted February 11, 2009 No error displayed! All go well, just the file isn't deleted, when I go check folder, the files remain there in the server. Did it display any messages? Such as "The permissions for the file" or "the file should be erased" If so please post those. If not, it never makes it to that point in the script and you have an error somewhere... Quote Link to comment https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759762 Share on other sites More sharing options...
jomagi Posted February 11, 2009 Author Share Posted February 11, 2009 It dont show anything, all run normaly with delete mysql record and redirect on finish, just the files don't erase from server folder. Quote Link to comment https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759770 Share on other sites More sharing options...
redarrow Posted February 11, 2009 Share Posted February 11, 2009 try this. <?php $logoname = $row["logotipo"]; if (file_exists($logoname)) { $fileinfo = substr(sprintf('%o', fileperms($logoname)), -4); echo 'The permissions for the file ' . $logonname . ' are: ' . $fileinfo . '<br />'; if (chmod( $logoname, 0777 )&& unlink($logoname)) { echo 'The file ' . $logoname . ' should be erased.<br />'; }else { echo 'The file ' . $logoname . ' was not erased.<br />'; } }else { echo 'The file does not exist!'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759780 Share on other sites More sharing options...
jomagi Posted February 11, 2009 Author Share Posted February 11, 2009 Same thing!!! No errors, do the same as before!!! Quote Link to comment https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759784 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.