Jump to content

Unlink


jomagi

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759591
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759598
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759601
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759605
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759631
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759709
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759712
Share on other sites

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...

Link to comment
https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759762
Share on other sites

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!';
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/144748-unlink/#findComment-759780
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.