|
Posted by nicemotion on 11/24/07 09:53
On 23 Nov, 19:31, Acrobatic <jbn...@gmail.com> wrote:
> Can we see the script/form that you specify the upload file with?
> Maybe you don't have the ENCTYPE set correctly. You'll need to set
> enctype to "multipart/form-data":
>
> ie:
>
> <form action="..." method="post" enctype="multipart/form-data"
> name="...">
>
> etc
>
> </form>
>
> On Nov 23, 10:37 am, nicemot...@gmail.com wrote:
>
> > Hi all,
>
> > the following easy script correctly insert a record in the DB but is
> > not moving the images (Logo and Foto) to the server /foto folder.
>
> > can't understand why 'cause the script is easy and correct and i guess
> > it loses the $file_temp var (actually the printout of $file_temp0
> > return nothing)
>
> > i even tryed to write it repeating the parameters i/o using variables
> > but no results.
>
> > Anyone can help ?
>
> > Many thanks in advance
>
> > Nik
>
> > -----------------------------------
>
> > if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1"))
> > {
>
> > //// set variables
> > $file_temp0=($_FILES['Logo']['tmp_name']);
> > $file_temp1=($_FILES['Foto']['tmp_name']);
>
> > //folder of the image on the server
> > $percorso="foto/";
>
> > $nuovo_nome0=$percorso.$_POST['Logo'];
> > $nuovo_nome1=$percorso.$_POST['Foto'];
>
> > $insertSQL = sprintf("INSERT INTO marcalinea (ID_MarcaLinea, Marca_,
> > LineaProdotto_, Logo, Foto, Descrizione, Pdf_) VALUES (%s, %s, %s, %s,
> > %s, %s, %s)",
> > GetSQLValueString($_POST['ID_MarcaLinea'],
> > "int"),
> > GetSQLValueString($_POST['Marca_'], "int"),
> > GetSQLValueString($_POST['LineaProdotto_'],
> > "int"),
> > GetSQLValueString($nuovo_nome0, "text"),
> > GetSQLValueString($nuovo_nome1, "text"),
> > GetSQLValueString($_POST['Descrizione'],
> > "text"),
> > GetSQLValueString($_POST['Pdf_'], "int"));
>
> > //print ($file_temp0); // return nothings
> > //print ($nuovo_nome0); // returns correctly /foto/img_name
>
> > mysql_select_db($database_Conn_Bianchi, $Conn_Bianchi);
> > $Result1 = mysql_query($insertSQL, $Conn_Bianchi) or
> > die(mysql_error());
>
> > ////Everything ok 'till here; the following does't works:
>
> > ######### upload image########
>
> > move_uploaded_file($file_temp0, $nuovo_nome0);
> > move_uploaded_file($_FILES["Foto"]["tmp_name"],"foto/" .
> > $_FILES["Foto"]["name"]);
>
> > ###############################
>
> > $insertGoTo = "view.php";
> > etc...
Hi Acrobat, this is the full script:
<?php require_once('Connections/Conn_Bianchi.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;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1"))
{
######Gestione Img###
$file_temp0=$_FILES['Logo']['tmp_name'];
$file_temp1=$_FILES['Foto']['tmp_name'];
$errore=$_FILES['Logo']['error'];
//file temporaneo che contiene l'immagine caricata
$percorso="foto/";
//cartella sul server dove verrà spostata la foto
$nuovo_nome0=$percorso.$_POST['Logo'];
$nuovo_nome1=$percorso.$_POST['Foto'];
#################
$insertSQL = sprintf("INSERT INTO marcalinea (ID_MarcaLinea, Marca_,
LineaProdotto_, Logo, Foto, Descrizione, Pdf_) VALUES (%s, %s, %s, %s,
%s, %s, %s)",
GetSQLValueString($_POST['ID_MarcaLinea'],
"int"),
GetSQLValueString($_POST['Marca_'], "int"),
GetSQLValueString($_POST['LineaProdotto_'],
"int"),
GetSQLValueString($nuovo_nome0, "text"),
GetSQLValueString($nuovo_nome1, "text"),
GetSQLValueString($_POST['Descrizione'],
"text"),
GetSQLValueString($_POST['Pdf_'], "int"));
print($errore);
mysql_select_db($database_Conn_Bianchi, $Conn_Bianchi);
$Result1 = mysql_query($insertSQL, $Conn_Bianchi) or
die(mysql_error());
######### sposto l'immagine nella cartella ########
move_uploaded_file($_FILES["Logo"]["tmp_name"],"foto/" .
$_FILES["Logo"]["name"]);
move_uploaded_file($file_temp1, $nuovo_nome1);
###############################
$insertGoTo = "view.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_Conn_Bianchi, $Conn_Bianchi);
$query_QryGeneral = "SELECT * FROM lineeprodotto, marcalinea, marche
WHERE marcalinea.Marca_ = marche.ID_Marche AND
marcalinea.LineaProdotto_ = lineeprodotto.ID_Linee";
$QryGeneral = mysql_query($query_QryGeneral, $Conn_Bianchi) or
die(mysql_error());
$row_QryGeneral = mysql_fetch_assoc($QryGeneral);
$totalRows_QryGeneral = mysql_num_rows($QryGeneral);
mysql_select_db($database_Conn_Bianchi, $Conn_Bianchi);
$query_QryMarche = "SELECT * FROM marche";
$QryMarche = mysql_query($query_QryMarche, $Conn_Bianchi) or
die(mysql_error());
$row_QryMarche = mysql_fetch_assoc($QryMarche);
$totalRows_QryMarche = mysql_num_rows($QryMarche);
mysql_select_db($database_Conn_Bianchi, $Conn_Bianchi);
$query_QryLineaProdotto = "SELECT * FROM lineeprodotto";
$QryLineaProdotto = mysql_query($query_QryLineaProdotto,
$Conn_Bianchi) or die(mysql_error());
$row_QryLineaProdotto = mysql_fetch_assoc($QryLineaProdotto);
$totalRows_QryLineaProdotto = mysql_num_rows($QryLineaProdotto);
mysql_select_db($database_Conn_Bianchi, $Conn_Bianchi);
$query_QryMarcaLinea = "SELECT * FROM marcalinea";
$QryMarcaLinea = mysql_query($query_QryMarcaLinea, $Conn_Bianchi) or
die(mysql_error());
$row_QryMarcaLinea = mysql_fetch_assoc($QryMarcaLinea);
$totalRows_QryMarcaLinea = mysql_num_rows($QryMarcaLinea);
?><!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>Documento senza titolo</title>
</head>
<body>
<form method="post" name="form1" action="<?php echo $editFormAction; ?
>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">ID_MarcaLinea:</td>
<td><input type="text" name="ID_MarcaLinea" value="" size="32"></
td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Marca_:</td>
<td><select name="Marca_">
<?php
do {
?>
<option value="<?php echo $row_QryMarche['ID_Marche']?>"><?php
echo $row_QryMarche['Marca']?></option>
<?php
} while ($row_QryMarche = mysql_fetch_assoc($QryMarche));
$rows = mysql_num_rows($QryMarche);
if($rows > 0) {
mysql_data_seek($QryMarche, 0);
$row_QryMarche = mysql_fetch_assoc($QryMarche);
}
?>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">LineaProdotto_:</td>
<td><select name="LineaProdotto_">
<?php
do {
?>
<option value="<?php echo $row_QryLineaProdotto['ID_Linee']?
>"><?php echo $row_QryLineaProdotto['LineaProdotto']?></option>
<?php
} while ($row_QryLineaProdotto =
mysql_fetch_assoc($QryLineaProdotto));
$rows = mysql_num_rows($QryLineaProdotto);
if($rows > 0) {
mysql_data_seek($QryLineaProdotto, 0);
$row_QryLineaProdotto = mysql_fetch_assoc($QryLineaProdotto);
}
?>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Logo
:</td>
<td><input name="Logo" type="file" id="Logo" /></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Foto
:</td>
<td><input name="Foto" type="file" id="Foto" /></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Descrizione:</td>
<td><input type="text" name="Descrizione" value="" size="32"></
td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Pdf_:</td>
<td><input type="text" name="Pdf_" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Inserisci record">
<input type="hidden" name="MM_insert" value="form1" /></td>
</tr>
</table>
</form>
</body>
</html>
<?php
mysql_free_result($QryGeneral);
mysql_free_result($QryMarche);
mysql_free_result($QryLineaProdotto);
mysql_free_result($QryMarcaLinea);
?>
[Back to original message]
|