<?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[Upload file e ridimensionamento automatico]]></title><description><![CDATA[<p dir="auto">Ciao a tutti, ho questa funzione che provvede a fare l'upload:</p>
<pre><code class="language-php">function uploadImage($filecontrol,$linkback) {
$est=strtolower(substr($_FILES[''.$filecontrol]['name'],-3,3));
if ($est!="") { 
if ($est=="jpg" || $est=="gif") {
if (isset($_FILES[''.$filecontrol]) &amp;&amp; is_uploaded_file($_FILES[''.$filecontrol]['tmp_name'])) // NUOVA IMMAGINE
{
if (move_uploaded_file($_FILES[''.$filecontrol]['tmp_name'], $_SESSION['PathUpload'].$_FILES[''.$filecontrol]['name'])==FALSE) 
{
if($_FILES[''.$filecontrol]['error']==2) {
redirect_rel($linkback);
exit();
} else {
redirect_rel($linkback);
exit();
}
} else {
$random= randomKey("",8);
$valo=Filesave(0,$random,$est,2);
}
if ($valo&gt;0) {
if(!rename($_SESSION['PathUpload'].$_FILES[''.$filecontrol]['name'],$_SESSION['PathUpload'].$valo."_".$random.".".$est ))
$logo=0;
else
$logo=$valo;
}
}
} 
if ($logo=="" || $logo&lt;0) $logo=0;
} else {
$logo=0;
}
 
return $logo;
}
</code></pre>
<p dir="auto">Ho poi trovato una funzione che riceve in ingresso il path del file da ridimensionare,_l'altezza e la larghezza massimi, ridimensiona in automatico affinchè non vengano superati i limiti massimi senza stretchare l'immagine stessa e infine salva il file ridimensionato nella posizione desiderata.</p>
<pre><code class="language-php">include("classe_resize.php");
$resize = new resize;
$resize-&gt;urlimage = "folder/immagine.jpg";
$resize-&gt;fisso = 0;
$resize-&gt;maxX = 300;
$resize-&gt;maxY = 150;
$resize-&gt;latofisso = "XY";
$resize-&gt;folder = "public/img/";
$resize-&gt;newName = "nuovonome.jpg";
$resize-&gt;go();
</code></pre>
<p dir="auto">Il problema è che non ho mai fatto upload di file, quindi non riesco a capire esattamente qual è il punto in cui il file viene mosso dalla directory temporanea alla directory finale. Se riuscissi a ridimensionare il file direttamente durante questo passaggio sarebbe perfetto...ma non ci riesco.:bho:</p>
<p dir="auto">Mi dareste una mano? <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/android/1f622.png?v=12b9555a9a1" class="not-responsive emoji emoji-android emoji--cry" style="height:1.4em;width:auto;vertical-align:middle" title=":cry:" alt="😢" /></p>
<p dir="auto">PS: a un certo punto c'è la funzione filesave. Questa ha solo il compito di memorizzare in una tabella del database il nome del file, l'estensione ed un random che viene poi accodato alla fine dell'id del file durante le varie chiamate successive).</p>
]]></description><link>https://dev.connect.gt/topic/87265/upload-file-e-ridimensionamento-automatico</link><generator>RSS for Node</generator><lastBuildDate>Thu, 26 Nov 2026 05:02:32 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/87265.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 09 Nov 2008 07:02:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Upload file e ridimensionamento automatico on Sun, 09 Nov 2008 17:54:16 GMT]]></title><description><![CDATA[<p dir="auto">Intanto grazie mille per la disponibilità.</p>
<p dir="auto">Il problema è che però quella funzione già gira su un sito e vorrei modificare proprio quella per evitare incasinamenti vari che potrebbero derivare rivoluzionando tutto...:x</p>
]]></description><link>https://dev.connect.gt/post/780478</link><guid isPermaLink="true">https://dev.connect.gt/post/780478</guid><dc:creator><![CDATA[ninonino]]></dc:creator><pubDate>Sun, 09 Nov 2008 17:54:16 GMT</pubDate></item><item><title><![CDATA[Reply to Upload file e ridimensionamento automatico on Sun, 09 Nov 2008 11:46:01 GMT]]></title><description><![CDATA[<pre><code class="language-php">&lt;?php require_once('Connections/image.php'); ?&gt;
&lt;?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"])) &amp;&amp; ($_POST["MM_insert"] == "form1")&amp;&amp; ($_FILES['new_image'])) {
  $insertSQL = sprintf("INSERT INTO immage (luogo, titolo, image_orig, image_small) VALUES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['luogo'], "text"),
                       GetSQLValueString($_POST['titolo'], "text"),
                       GetSQLValueString($_FILES['new_image']['name'], "text"),
                       GetSQLValueString($_FILES['new_image'] ['name'], "text"));
  mysql_select_db($database_image, $image);
  $Result1 = mysql_query($insertSQL, $image) or die(mysql_error());
}
?&gt;&lt;form name="form1" action="&lt;?php echo $editFormAction; ?&gt;" method="POST" enctype="multipart/form-data" id="something" class="uniForm"&gt;
        &lt;input name="new_image" id="new_image" size="30" type="file" class="fileUpload" /&gt;
        &lt;button name="submit" type="submit" class="submitButton"&gt;Upload/Resize Image&lt;/button&gt;
  &lt;p&gt;&amp;nbsp;&lt;/p&gt;
        &lt;p&gt;
          &lt;label&gt;
          &lt;input name="luogo" type="text" id="luogo" /&gt;
          &lt;/label&gt;
        &lt;/p&gt;
        &lt;p&gt;
          &lt;label&gt;
          &lt;input name="titolo" type="text" id="titolo" /&gt;
          &lt;/label&gt;
        &lt;/p&gt;
        &lt;p&gt;&amp;nbsp;&lt;/p&gt;
        &lt;input type="hidden" name="MM_insert" value="form1"&gt;
&lt;/form&gt;
&lt;?php
        if(isset($_POST['submit'])&amp;&amp; $_FILES['new_image']){
          if (isset ($_FILES['new_image'])){
              $imagename = $_FILES['new_image']['name'];
              $source = $_FILES['new_image']['tmp_name'];
              $target = "images/".$imagename;
              move_uploaded_file($source, $target);
              
              $imagepath = $imagename;
              $save = "images_resize/150_" . $imagepath; //This is the new file you saving
              $file = "images/" . $imagepath; //This is the original file
              list($width, $height) = getimagesize($file) ; 
                                                         
              $modwidth = 150; 
                                                         
              $diff = $width / $modwidth;
                                                        
              $modheight = $height / $diff; 
              $tn = imagecreatetruecolor($modwidth, $modheight) ; 
              $image = imagecreatefromjpeg($file) ; 
              imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
                                                        
              imagejpeg($tn, $save, 100) ; 
              $save = "images_resize/" . $imagepath; //This is the new file you saving 
              $file = "images/" . $imagepath; //This is the original file
              list($width, $height) = getimagesize($file) ; 
                                                         
              $modwidth = 80; 
                                                         
              $diff = $width / $modwidth;
                                                        
              $modheight = $height / $diff; 
              $tn = imagecreatetruecolor($modwidth, $modheight) ; 
              $image = imagecreatefromjpeg($file) ; 
              imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
                                                        
              imagejpeg($tn, $save, 100) ; 
            
        
          }
        }
?&gt;
</code></pre>
<p dir="auto">tratto da dreamweaver pero' modificabile come vuoi..</p>
]]></description><link>https://dev.connect.gt/post/780466</link><guid isPermaLink="true">https://dev.connect.gt/post/780466</guid><dc:creator><![CDATA[patatrac]]></dc:creator><pubDate>Sun, 09 Nov 2008 11:46:01 GMT</pubDate></item></channel></rss>