Salve a tutti,
avendo questo script:
Codice PHP:
<?php ini_set("memory_limit", "200000000"); // per le immagini di grandi dimensioni in modo che non si ottiene "memoria esaurita ammessi"?>
<?php
// caricare il file
if ((isset($_POST["submitted_form"])) && ($_POST["submitted_form"] == "image_upload_form")) {
// file deve essere jpg, gif, bmp, png e x-max 4 MB
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") && ($_FILES["image_upload_box"]["size"] < 4000000))
{
// alcune impostazioni
$max_upload_width = 2592;
$max_upload_height = 1944;
// se l'utente chosed correttamente poi ridimensionare l'immagine secondo preferances utente
if(isset($_REQUEST['max_width_box']) and $_REQUEST['max_width_box']!='' and $_REQUEST['max_width_box']<=$max_upload_width){
$max_upload_width = $_REQUEST['max_width_box'];
}
if(isset($_REQUEST['max_height_box']) and $_REQUEST['max_height_box']!='' and $_REQUEST['max_height_box']<=$max_upload_height){
$max_upload_height = $_REQUEST['max_height_box'];
}
// se l'immagine è stata caricata 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"]);
}
// se l'immagine è stata caricata GIF
if($_FILES["image_upload_box"]["type"] == "image/gif"){
$image_source = imagecreatefromgif($_FILES["image_upload_box"]["tmp_name"]);
}
// BMP non sembra essere sostenuti in modo rimuoverlo modulo di cui sopra test immagine tipo (rifiutare BMPS)
// se l'immagine è stata caricata BMP
if($_FILES["image_upload_box"]["type"] == "image/bmp"){
$image_source = imagecreatefromwbmp($_FILES["image_upload_box"]["tmp_name"]);
}
// se l'immagine è stata caricata PNG
if($_FILES["image_upload_box"]["type"] == "image/x-png"){
$image_source = imagecreatefrompng($_FILES["image_upload_box"]["tmp_name"]);
}
$remote_file = "image_files/".$_FILES["image_upload_box"]["name"];
imagejpeg($image_source,$remote_file,100);
chmod($remote_file,0644);
// ottenere la larghezza e l'altezza dell'immagine originale
list($image_width, $image_height) = getimagesize($remote_file);
if($image_width>$max_upload_width || $image_height >$max_upload_height){
$proportions = $image_width/$image_height;
if($image_width>$image_height){
$new_width = $max_upload_width;
$new_height = round($max_upload_width/$proportions);
}
else{
$new_height = $max_upload_height;
$new_width = round($max_upload_height*$proportions);
}
$new_image = imagecreatetruecolor($new_width , $new_height);
$image_source = imagecreatefromjpeg($remote_file);
imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
imagejpeg($new_image,$remote_file,100);
imagedestroy($new_image);
}
imagedestroy($image_source);
header("Location: submit.php?upload_message=image uploaded&upload_message_type=success&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&upload_message_type=error");
exit;
}
}
?>
<!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=utf-8" />
<title>Carica e Ridimensiona immagine</title>
<style type="text/css">
<!--
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;
}
-->
</style></head>
<body>
<h1 style="margin-bottom: 0px">Invia un immagine</h1>
<?php if(isset($_REQUEST['upload_message'])){?>
<div class="upload_message_<?php echo $_REQUEST['upload_message_type'];?>">
<?php echo htmlentities($_REQUEST['upload_message']);?>
</div>
<?php }?>
<form action="submit.php" method="post" enctype="multipart/form-data" name="image_upload_form" id="image_upload_form" style="margin-bottom:0px;">
<label>La dimensione massima dell'immagine deve essere di: 4MB. Supporta i seguenti formati: jpg, gif, png:</label>
<input name="image_upload_box" type="file" id="image_upload_box" size="40" />
<input type="submit" name="submit" value="Upload image" />
<label>Ridimensiona Immagine? (2592 x 1944 px max):</label>
<input name="max_width_box" type="text" id="max_width_box" value="1024" size="4">
x
<input name="max_height_box" type="text" id="max_height_box" value="768" size="4">
px.
<p style="padding:5px; border:1px solid #EBEBEB; background-color:#FAFAFA;">
[b]Nota:[/b]
L'immagine non sarà portata esattamente a questa risoluzione; it will be scalled down so that neider width or height is larger than specified.
<span id="result_box" lang="it" xml:lang="it"><span title="">Durante il caricamento di questo script assicuratevi di avere una directory chiamata "image_files"con i permessi 777.</span></span>
</p>
<input name="submitted_form" type="hidden" id="submitted_form" value="image_upload_form" />
</form>
<?php if(isset($_REQUEST['show_image']) and $_REQUEST['show_image']!=''){?>
[img]image_files/<?php echo $_REQUEST['show_image'];?>[/img]
</p>
<?php }?>
</body>
</html>
Il quale dovrebbe farmi fare l'upload di immagini in una cartella predefinita all'interno del codice (image_file)..
Io invce vorrei un campo form opzionale a tendina dal quale poter selezionare in quale cartella questa img debba essere salvata..
Qualcuno può aiutarmi?
Grazie Anticipatamente a quanti si proporranno.!!