Reputation: 1
I have a problem while resizing an array of images on multyupload.
Normally I use Simple Image Resizer for a single image, but I can't resize a group of items using an array... where am I going wrong?
<?php
session_start();
$serverpath = "C:\EasyPHP-12.1\www\www.arcasarda.pet\\";
$uploaddir = $serverpath."img/pagine/";
if(count($_FILES) > 0) {
$id=$_POST['id'];
$arrfile = pos($_FILES);
$file = $id.'_'.stripslashes(basename($arrfile['name']));
$uploadfile = $uploaddir . $file;
if (move_uploaded_file($arrfile['tmp_name'], $uploadfile)) {
$img_path = $uploadfile;
$size = @getimagesize ($img_path);
if ($size[0] > $size[1]) {
resize_larghezzafissa ($img_path,1500);
} else {
resize_altezzafissa ($img_path,1500);
}
chmod($uploadfile, 0777);
include $serverpath."/db_connection.php";
$query = "SELECT MAX(ordine) FROM testi_img WHERE id_testo='$id'";
$result=mysql_query($query);
list($max)=mysql_fetch_row($result);
$ordine=$max+1;
$query="SET SESSION sql_mode=''";
mysql_query($query);
$query = "INSERT INTO testi_img (id_testo, img, dida, ordine) VALUES ('$id', '$file', '{italiano}{/italiano}', '$ordine')";
mysql_query($query);
}
}
Below is the function used in conjunction with the Simple Image Resizer class
function resize_larghezzafissa($src, $witdh){
include($serverpath.'/php/SimpleImage.php');
$image = new SimpleImage();
$image->load($src);
$image->resizeToWidth($witdh);
$image->save($src, IMAGETYPE_JPEG, 100, null);
}
function resize_altezzafissa($src, $height){
include($serverpath.'/php/SimpleImage.php');
$image = new SimpleImage();
$image->load($src);
$image->resizeToHeight($height);
$image->save($src, IMAGETYPE_JPEG, 100, null);
}
?>
Upvotes: 0
Views: 37
Reputation: 1
PS: For a single file I use this script, which works:
if (is_uploaded_file($_FILES['img']['tmp_name'])){
$tipo=$_FILES['img']['type'];
if ($tipo=="image/pjpeg" || $tipo=="image/jpeg"){
$img=$id.'_'.str_replace(" ", "_", $_FILES['img']['name']);
$img_path = _IMG_FOLDER.$img;
copy($_FILES['img']['tmp_name'], $img_path);
$size = @getimagesize ($img_path);
if ($size[0] > $size[1]) {
resize_larghezzafissa ($img_path,_IMG_RESIZE);
} else {
resize_altezzafissa ($img_path,_IMG_RESIZE);
}
@chmod($img_path, 0777);
} else {
echo '<p>Formato immagine non supportato.</p>';
}
if (file_exists($img_path)){
// elimino la vecchia immagine
@unlink(_IMG_FOLDER.$_POST['old_img']);
// scrivo sul db il nome della nuova immagine
$query="UPDATE testi_sez
SET img='$img'
WHERE id='$id'";
if (mysql_query($query)){
if (mysql_affected_rows()==1){
echo '<p><strong>Immagine Inserita</strong></p>';
} else {
echo '<p><strong>ERRORE! Immagine NON Inserita</strong></p>';
}
}
} else {
echo '<p><strong>ERRORE! Immagine NON Inserita</strong></p>';
}
}
Upvotes: 0