<?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[Rinominare immagini in upload]]></title><description><![CDATA[<p dir="auto">Ho creato questo script che permette di fare il ridimensionamento e l'upload di foto, ora vorrei accodare al nome della foto caricata una stringa del tipo "NOMEFOTO**-small**.jpg" però non riesco a capire come fare, mi potete aiutare.</p>
<p dir="auto">Questo è il codice:</p>
<pre><code class="language-php">&lt;?php ini_set("memory_limit", "200000000"); // for large images so that we do not get "Allowed memory exhausted"?&gt;
&lt;?php
// upload the file
if ((isset($_POST["submitted_form"])) &amp;&amp; ($_POST["submitted_form"] == "image_upload_form")) {
 // file needs to be jpg,gif,bmp,x-png and 4 MB max
 if (($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg" || $_FILES["image_upload_box"]["type"] == "image/gif" || $_FILES["image_upload_box"]["type"] == "image/x-png") &amp;&amp; ($_FILES["image_upload_box"]["size"] &lt; 4000000))
 {
  // if uploaded image was JPG/JPEG
  if($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg"){
   $image_source = imagecreatefromjpeg($_FILES["image_upload_box"]["tmp_name"]);
  }
  // if uploaded image was GIF
  if($_FILES["image_upload_box"]["type"] == "image/gif"){
   $image_source = imagecreatefromgif($_FILES["image_upload_box"]["tmp_name"]);
  }
  // BMP doesn't seem to be supported so remove it form above image type test (reject bmps)
  // if uploaded image was BMP
  if($_FILES["image_upload_box"]["type"] == "image/bmp"){
   $image_source = imagecreatefromwbmp($_FILES["image_upload_box"]["tmp_name"]);
  }
  // if uploaded image was PNG
  if($_FILES["image_upload_box"]["type"] == "image/x-png"){
   $image_source = imagecreatefrompng($_FILES["image_upload_box"]["tmp_name"]);
  }
  $remote_file = "foto/".$_FILES["image_upload_box"]["name"];
  imagejpeg($image_source,$remote_file,80);
  chmod($remote_file,0644);
  $new_w = 120;
  $new_h = 120;
  $orig_w = imagesx($image_source);
  $orig_h = imagesy($image_source);
 
  $w_ratio = ($new_w / $orig_w);
  $h_ratio = ($new_h / $orig_h);
  // PAESAGGIO
  if ($orig_w &gt; $orig_h ) {
   $crop_w = round($orig_w * $h_ratio);
   $crop_h = $new_h;
   $x = ($orig_w - $orig_h) / 2;
 
  // RITRATTO
  } elseif ($orig_w &lt; $orig_h ) {
   $crop_h = round($orig_h * $w_ratio);
   $crop_w = $new_w;
   $y = ($orig_h - $orig_w) /2;
  // QUADRATO
  } else {
   $crop_w = $new_w;
   $crop_h = $new_h;
  }
  $new_image = imagecreatetruecolor($new_w,$new_h);
  $image_source = imagecreatefromjpeg($remote_file);
  imagecopyresampled($new_image, $image_source, 0, 0, $x, $y, $crop_w, $crop_h, $orig_w, $orig_h);
  imagejpeg($new_image,$remote_file,80);
  imagedestroy($new_image);
  imagedestroy($image_source);
 
  header("Location: submit.php?upload_message=image uploaded&amp;upload_message_type=success&amp;show_image=".$_FILES["image_upload_box"]["name"]);
  exit;
 }
 else{
  header("Location: submit.php?upload_message=make sure the file is jpg, gif or png and that is smaller than 4MB&amp;upload_message_type=error");
  exit;
 }
}
?&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "..."&gt;
&lt;html xmlns="..."&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Image Upload with resize&lt;/title&gt;
&lt;style type="text/css"&gt;
&lt;!--
body,td,th {
 font-family: Arial, Helvetica, sans-serif;
 color: #333333;
 font-size: 12px;
}
.upload_message_success {
 padding:4px;
 background-color:#009900;
 border:1px solid #006600;
 color:#FFFFFF;
 margin-top:10px;
 margin-bottom:10px;
}
.upload_message_error {
 padding:4px;
 background-color:#CE0000;
 border:1px solid #990000;
 color:#FFFFFF;
 margin-top:10px;
 margin-bottom:10px;
}
--&gt;
&lt;/style&gt;&lt;/head&gt;
&lt;body&gt;
&lt;h1 style="margin-bottom: 0px"&gt;INSERIMENTO IMMAGINE&lt;/h1&gt;
 
        &lt;?php if(isset($_REQUEST['upload_message'])){?&gt;
            &lt;div class="upload_message_&lt;?php echo $_REQUEST['upload_message_type'];?&gt;"&gt;
            &lt;?php echo htmlentities($_REQUEST['upload_message']);?&gt;
            &lt;/div&gt;
  &lt;?php }?&gt;
 
&lt;form action="submit.php" method="post" enctype="multipart/form-data" name="image_upload_form" id="image_upload_form" style="margin-bottom:0px;"&gt;
&lt;label&gt;- Dimensione massima: 4MB - Estensioni possibili: jpg, gif, png.&lt;/label&gt;&lt;br /&gt;
          &lt;input name="image_upload_box" type="file" id="image_upload_box" size="40" /&gt;
          &lt;input type="submit" name="submit" value="Upload image" /&gt;
     &lt;br /&gt;
 &lt;br /&gt;
 
&lt;input name="submitted_form" type="hidden" id="submitted_form" value="image_upload_form" /&gt;
&lt;/form&gt;
 
 
&lt;?php if(isset($_REQUEST['show_image']) and $_REQUEST['show_image']!=''){?&gt;
&lt;p&gt;
 &lt;img src="foto/&lt;?php echo $_REQUEST['show_image'];?&gt;" /&gt;
&lt;/p&gt;
&lt;?php }?&gt;
 
 
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p dir="auto">GRAZIE</p>
]]></description><link>https://dev.connect.gt/topic/135781/rinominare-immagini-in-upload</link><generator>RSS for Node</generator><lastBuildDate>Sun, 29 Nov 2026 16:24:59 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/135781.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 26 Sep 2010 10:49:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Rinominare immagini in upload on Sun, 26 Sep 2010 11:46:42 GMT]]></title><description><![CDATA[<p dir="auto">Non credo di aver capito bene come fare, prima della funzione imagejpeg ho provato a far assumere alla variabile $new_image una scringa di 4 caratteri però non funziona.</p>
<p dir="auto">Quello che vorrei riuscire a fare è salvare la stessa immagine 2 vole, una con il nome originale e una con il nome modificato, però ci riesco.</p>
<p dir="auto">Qualcun'altro ha delle idee su come farlo?</p>
<p dir="auto">Non so proprio come fare.</p>
]]></description><link>https://dev.connect.gt/post/937957</link><guid isPermaLink="true">https://dev.connect.gt/post/937957</guid><dc:creator><![CDATA[darkf3d3]]></dc:creator><pubDate>Sun, 26 Sep 2010 11:46:42 GMT</pubDate></item><item><title><![CDATA[Reply to Rinominare immagini in upload on Sun, 26 Sep 2010 11:23:05 GMT]]></title><description><![CDATA[<p dir="auto">Ciao DARKF3D3,</p>
<p dir="auto">devi modificare il nome nel primo parametro della funzione imagecopyresampled.</p>
]]></description><link>https://dev.connect.gt/post/937934</link><guid isPermaLink="true">https://dev.connect.gt/post/937934</guid><dc:creator><![CDATA[thedarkita]]></dc:creator><pubDate>Sun, 26 Sep 2010 11:23:05 GMT</pubDate></item></channel></rss>