Ver Mensaje Individual
  #3 (permalink)  
Antiguo 22/11/2007, 12:46
gustavobaezz
 
Fecha de Ingreso: noviembre-2007
Mensajes: 90
Antigüedad: 16 años, 5 meses
Puntos: 0
Re: Problema con el comando unlink

Lo primero muchas gracias por contestar....te has ganado un amigo.

Por otro lado....tienes razón en lo de las comillas en $_POST['textfield'];...lo he publicado así porque de tantas pruebas que he hecho no me he dado cuenta y eso estaba mal.

Por cierto... el servidor no me da respuesta de error ninguna, he probado tu script y tampoco... creo que está relacionado con lo que te contaré ahora.

Te endico la siguiente información por si me puedes ayudar:

Este pequeño script va insertado en una página php que básicamente muestra los resultados de una base de datos mysql en un formulario y con esa información al enviarlo se debe borrar el registro y a la vez borrar el archivo referenciado en uno de los campos..... se que es una chapuza...que sería mejor poner un radiobutton como opción para borrar el archivo...pero quiero que se haga todo con el botón enviar para evitar que alguien borre los datos de la tabla mysql sin haber borrado el archivo....

Fuera como fuese...en mi servidor apache 2.2 con php 5.2.1 funciona correctamente, mientras que en proveedor de hosting (no sabía que no se podían nombrar...lo siento) no funciona.

Te envío el archivo completo a ver si encuentras el fallo:


<?php require_once('../Connections/basedatos.php'); ?>
<?php
session_start();
$MM_authorizedUsers = "administrador";
$MM_donotCheckaccess = "false";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;

// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && false) {
$isValid = true;
}
}
return $isValid;
}

$MM_restrictGoTo = "/mantenimiento/login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?php
$currentPage = $_SERVER["PHP_SELF"];

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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($_POST['textfield25'])) && ($_POST['textfield25'] != "")) {
$deleteSQL = sprintf("DELETE FROM feeditems WHERE itemID=%s",
GetSQLValueString($_POST['textfield25'], "int"));

mysql_select_db($database_basedatos, $basedatos);
$Result1 = mysql_query($deleteSQL, $basedatos) or die(mysql_error());
}

$maxRows_Recordset1 = 1;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_basedatos, $basedatos);
$query_Recordset1 = "SELECT * FROM feeditems ORDER BY itemID DESC";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $basedatos) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

$queryString_Recordset1 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_Recordset1") == false &&
stristr($param, "totalRows_Recordset1") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
?>
<?php
//Esta parte de codigo esta generada por Gustavo para borrar adjuntos
//codigo propio
//codigo propio
$vinculo=$_POST['textfield'];
$vinculo="(substr ($vinculo,40))";
if ($Submit) {
unlink ($vinculo);
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

<body>
<p>&nbsp;</p>
<form name="form1" method="post" action="">
<?php do { ?>
<p>
<input name="textfield25" type="hidden" value="<?php echo $row_Recordset1['itemID']; ?>">
</p>
<p align="center">Fecha de publicaci&oacute;n: </p>
<p align="center"><?php echo $row_Recordset1['ItemAddedTime']; ?></p>
<p align="center">Titular de noticia: </p>
<p align="center">
<textarea name="textfield24" cols="60"><?php echo $row_Recordset1['ItemTitle']; ?></textarea>
</p>
<p align="center">Noticia insertada en: </p>
<p align="center"><?php echo $row_Recordset1['ItemDescription']; ?> </p>
<p align="center">V&iacute;nculo:</p>
<p align="center">
<textarea name="textfield" cols="120"><?php echo $row_Recordset1['ItemLink']; ?></textarea>
</p>
<p align="center">Adjunto: (Tambi&eacute;n se borrar&aacute;...pero si se intenta borrar y este campo est&aacute; vacio, la p&aacute;gina dar&aacute; un error...pese a todo se borrar&aacute; el registro) </p>
<p align="center">
<textarea name="textfield2" cols="120"><?php echo $row_Recordset1['ItemEnclosureUrl']; ?></textarea>
</p>
<p align="center">
<input type="submit" name="Submit" value="Borrar">
</p>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
<table border="0" width="50%" align="center">
<tr>
<td width="23%" align="center">
<?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0, $queryString_Recordset1); ?>"><img src="First.gif" border=0></a>
<?php } // Show if not first page ?>
</td>
<td width="31%" align="center">
<?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>"><img src="Previous.gif" border=0></a>
<?php } // Show if not first page ?>
</td>
<td width="23%" align="center">
<?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>"><img src="Next.gif" border=0></a>
<?php } // Show if not last page ?>
</td>
<td width="23%" align="center">
<?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, $totalPages_Recordset1, $queryString_Recordset1); ?>"><img src="Last.gif" border=0></a>
<?php } // Show if not last page ?>
</td>
</tr>
</table>
</form>
<p>&nbsp;
</p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>


Gracias