Jump to content

Upload problem


pacognovellino

Recommended Posts

Hi,I have this script that is soposed to update a record in a table, the thing is that is work walf way, because it doesnt update the image here is the code:

<?php require_once('Connections/paco_not.php'); ?>

<?php

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;

}

 

$editFormAction = $_SERVER['PHP_SELF'];

if (isset($_SERVER['QUERY_STRING'])) {

  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

}

 

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

  $insertSQL = sprintf("INSERT INTO upload (noticia, fecha, comentario) VALUES (%s, %s, %s)",

                      GetSQLValueString($_POST['noticia'], "text"),

                      GetSQLValueString($_POST['fecha'], "date"),

                      GetSQLValueString($_POST['comentario'], "text"));

 

  mysql_select_db($database_paco_not, $paco_not);

  $Result1 = mysql_query($insertSQL, $paco_not) or die(mysql_error());

 

  $insertGoTo = "index.php";

  if (isset($_SERVER['QUERY_STRING'])) {

    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";

    $insertGoTo .= $_SERVER['QUERY_STRING'];

  }

  header(sprintf("Location: %s", $insertGoTo));

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

<style type="text/css">

<!--

body {

margin-top: 0px;

}

-->

</style></head>

 

<body>

<table width="64%" border="0" align="center" cellpadding="4" cellspacing="0">

  <tr align="center" bgcolor="#999999">

    <td colspan="3">Agregar Noticia </td>

  </tr>

  <tr>

    <td><a href="#"><img src="" name="Logo" width="150" height="70" border="0" style="background-color: #CCCC99" /></a></td>

    <td align="right"><img name="Image" src="" width="70" height="70" style="background-color: #CCFF99" /></td>

    <td><p><br />

    </p></td>

  </tr>

  <tr>

    <td height="119" colspan="3" valign="top"> 

      <form method="post" name="form1" action="<?php echo $editFormAction; ?>">

        <table align="center">

          <tr valign="baseline">

            <td nowrap align="right">Fecha:</td>

            <td><input type="text" name="fecha" value="" size="32"></td>

          </tr>

          <tr valign="baseline">

            <td nowrap align="right" valign="top">Comentario:</td>

            <td><textarea name="comentario" cols="50" rows="5"></textarea>

            </td>

          </tr>

          <tr valign="baseline">

            <td nowrap align="right" valign="top">Noticia:</td>

            <td><textarea name="noticia" cols="50" rows="5"></textarea>

            </td>

          </tr>

          <tr valign="baseline">

            <td nowrap align="right">Imagen:</td>

            <td><input type="file" name="path" value="" size="32"></td>

          </tr>

          <tr valign="baseline">

            <td nowrap align="right"> </td>

            <td><input name="insert" type="submit" id="insert" value="Insert record"></td>

          </tr>

        </table>

        <input type="hidden" name="MM_insert" value="form1">

      </form>

    <p> </p></td>

  </tr>

</table>

 

</body>

</html>

<?php

$uploadDir = 'C:/AppServ/www/paco/img/';

/* $dir cambia el nombre del directorio a img/ */

$dir = 'img/';

 

if(isset($_POST['insert']))

{

$fileName = $_FILES['FORM.path']['name'];

$tmpName = $_FILES['FORM.path']['tmp_name'];

$fileSize = $_FILES['FORM.path']['size'];

$fileType = $_FILES['FORM.path']['type'];

 

$filePath = $dir . $fileName;

 

$result = move_uploaded_file($tmpName, $filePath);

if (!$result) {

echo "Error subiendo archivo";

exit;

}

 

include 'Connections/paco_not.php';

 

if(!get_magic_quotes_gpc())

{

$fileName = addslashes($fileName);

$filePath = addslashes($filePath);

}

 

$query = "INSERT INTO upload (name, size, type, path) ".

"VALUES ('$fileName', '$fileSize', '$fileType', '$filePath')";

 

mysql_query($query) or die('Error, query failed : ' . mysql_error());

 

echo "<br>Archivo cargado<br>";

 

}

?>

 

Please help me out ??? ??? ???

Link to comment
https://forums.phpfreaks.com/topic/39747-upload-problem/
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.