<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Unire script upload con pagina inserimento]]></title><description><![CDATA[<p dir="auto">Salve ragazzi, vi posto il mio problema:<br />
dunque ho una pagina per inserire dei prodotti e uno script trovato in rete per l' upload delle immagini. Ora come potrei unire le due cose?  altrimentimenti dovrei prima effettuare l'upload della foto e poi nella pagina di inserimento far e di nuovo l'upload per fagli stampare il path.</p>
<p dir="auto">Il problema è che i form delle due pagine hanno diversi tipi di "azione"</p>
<p dir="auto">nella pagina di inserimento prodotti, l'azione è:<br />
&lt;?php echo $editFormAction; ?&gt;</p>
<p dir="auto">invece nella pagina dell'upload l'azione è:<br />
submit.php?subpage=upload</p>
<p dir="auto">questa è la pagina di inserimento prodotti:</p>
<p dir="auto">&lt;?php<br />
if (!function_exists("GetSQLValueString")) {<br />
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")<br />
{<br />
if (PHP_VERSION &lt; 6) {<br />
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;<br />
}</p>
<p dir="auto">$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);</p>
<p dir="auto">switch ($theType) {<br />
case "text":<br />
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";<br />
break;<br />
case "long":<br />
case "int":<br />
$theValue = ($theValue != "") ? intval($theValue) : "NULL";<br />
break;<br />
case "double":<br />
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";<br />
break;<br />
case "date":<br />
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";<br />
break;<br />
case "defined":<br />
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;<br />
break;<br />
}<br />
return $theValue;<br />
}<br />
}</p>
<p dir="auto">$editFormAction = $_SERVER['PHP_SELF'];<br />
if (isset($_SERVER['QUERY_STRING'])) {<br />
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);<br />
}</p>
<p dir="auto">if ((isset($_POST["MM_insert"])) &amp;&amp; ($_POST["MM_insert"] == "form1")) {<br />
$insertSQL = sprintf("INSERT INTO prodotti (id_menu, codice, titolo, prezzo, foto, foto_thumbs, scheda) VALUES (%s, %s, %s, %s, %s, %s, %s)",<br />
GetSQLValueString($_POST['id_menu'], "text"),<br />
GetSQLValueString($_POST['codice'], "text"),<br />
GetSQLValueString($_POST['titolo'], "text"),<br />
GetSQLValueString($_POST['prezzo'], "double"),<br />
GetSQLValueString($_FILES['foto']['name'], "text"),<br />
GetSQLValueString($_FILES['foto']['name'], "text"),<br />
GetSQLValueString($_POST['scheda'], "text"));</p>
<p dir="auto">mysql_select_db($database_conn, $conn);<br />
$Result1 = mysql_query($insertSQL, $conn) or die(mysql_error());<br />
}</p>
<p dir="auto">mysql_select_db($database_conn, $conn);<br />
$query_rs_menu = "SELECT * FROM menu ORDER BY nome_menu ASC";<br />
$rs_menu = mysql_query($query_rs_menu, $conn) or die(mysql_error());<br />
$row_rs_menu = mysql_fetch_assoc($rs_menu);<br />
$totalRows_rs_menu = mysql_num_rows($rs_menu);</p>
<p dir="auto">mysql_select_db($database_conn, $conn);<br />
$query_rs_inserisci_prodotto = "SELECT foto, foto_thumbs FROM prodotti";<br />
$rs_inserisci_prodotto = mysql_query($query_rs_inserisci_prodotto, $conn) or die(mysql_error());<br />
$row_rs_inserisci_prodotto = mysql_fetch_assoc($rs_inserisci_prodotto);<br />
$totalRows_rs_inserisci_prodotto = mysql_num_rows($rs_inserisci_prodotto);<br />
?&gt;</p>
<p dir="auto">questa è la pagina invece che fa l'upload della foto</p>
<p dir="auto">&lt;?php<br />
$idir = "image_files/";   // Path To Images Directory<br />
$tdir = "image_files/thumbs/";   // Path To Thumbnails Directory<br />
$twidth = "120";   // Maximum Width For Thumbnail Images<br />
$theight = "125";   // Maximum Height For Thumbnail Images</p>
<p dir="auto">if (!isset($_GET['subpage'])) {   // Image Upload Form Below   ?&gt;<br />
&lt;table width="500" border="0" align="center" cellpadding="1" cellspacing="1"&gt;<br />
&lt;tr&gt;<br />
&lt;th scope="col"&gt;&lt;form method="post" action="submit.php?subpage=upload" enctype="multipart/form-data"&gt;<br />
File:&lt;br /&gt;<br />
&lt;input type="file" name="foto" class="form"&gt;<br />
&lt;br /&gt;&lt;br /&gt;<br />
&lt;input name="Carica la foto" type="submit" value="Carica la foto" class="form" id="Carica la foto"&gt;<br />
&lt;/form&gt;<br />
&lt;? } else  if (isset($_GET['subpage']) &amp;&amp; $_GET['subpage'] == 'upload') {   // Uploading/Resizing Script<br />
$url = $_FILES['foto']['name'];   // Set $url To Equal The Filename For Later Use<br />
if ($_FILES['foto']['type'] == "image/jpg" || $_FILES['foto']['type'] == "image/jpeg" || $_FILES['foto']['type'] == "image/pjpeg") {<br />
$file_ext = strrchr($_FILES['foto']['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php<br />
$copy = copy($_FILES['foto']['tmp_name'], "$idir" . $_FILES['foto']['name']);   // Move Image From Temporary Location To Permanent Location<br />
if ($copy) {   // If The Script Was Able To Copy The Image To It's Permanent Location<br />
print 'Immagine caricata CORETTAMENTE.&lt;br /&gt;';   // Was Able To Successfully Upload Image<br />
$simg = imagecreatefromjpeg("$idir" . $url);   // Make A New Temporary Image To Create The Thumbanil From<br />
$currwidth = imagesx($simg);   // Current Image Width<br />
$currheight = imagesy($simg);   // Current Image Height<br />
if ($currheight &gt; $currwidth) {   // If Height Is Greater Than Width<br />
$zoom = $twidth / $currheight;   // Length Ratio For Width<br />
$newheight = $theight;   // Height Is Equal To Max Height<br />
$newwidth = $currwidth * $zoom;   // Creates The New Width<br />
} else {    // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)<br />
$zoom = $twidth / $currwidth;   // Length Ratio For Height<br />
$newwidth = $twidth;   // Width Is Equal To Max Width<br />
$newheight = $currheight * $zoom;   // Creates The New Height<br />
}<br />
$dimg = imagecreate($newwidth, $newheight);   // Make New Image For Thumbnail<br />
imagetruecolortopalette($simg, false, 256);   // Create New Color Pallete<br />
$palsize = ImageColorsTotal($simg);<br />
for ($i = 0; $i &lt; $palsize; $i++) {   // Counting Colors In The Image<br />
$colors = ImageColorsForIndex($simg, $i);   // Number Of Colors Used<br />
ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']);   // Tell The Server What Colors This Image Will Use<br />
}<br />
imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);   // Copy Resized Image To The New Image (So We Can Save It)<br />
imagejpeg($dimg, "$tdir" . $url);   // Saving The Image<br />
imagedestroy($simg);   // Destroying The Temporary Image<br />
imagedestroy($dimg);   // Destroying The Other Temporary Image<br />
print 'miniatura creata correttamente';   // Resize successful<br />
} else {<br />
print '&lt;font color="#FF0000"&gt;ERROR: Unable to upload image.&lt;/font&gt;';   // Error Message If Upload Failed<br />
}<br />
} else {<br />
print '&lt;font color="#FF0000"&gt;ERROR: Wrong filetype (has to be a .jpg or .jpeg. Yours is ';   // Error Message If Filetype Is Wrong<br />
print $file_ext;   // Show The Invalid File's Extention<br />
print '.&lt;/font&gt;';<br />
}<br />
} ?&gt;</p>
]]></description><link>https://connect.gt/topic/125068/unire-script-upload-con-pagina-inserimento</link><generator>RSS for Node</generator><lastBuildDate>Sat, 04 Apr 2026 07:25:48 GMT</lastBuildDate><atom:link href="https://connect.gt/topic/125068.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 08 Apr 2010 14:45:53 GMT</pubDate><ttl>60</ttl></channel></rss>