PHP通过SimpleImage类调整大小后的Multiupload图像

hrysbysz  于 2023-03-28  发布在  PHP
关注(0)|答案(1)|浏览(112)

我在multyupload上调整图像数组大小时遇到问题。
通常情况下,我使用简单的图像大小调整器为一个单一的图像,但我不能调整一组项目使用数组...我哪里出错了?

<?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);
    }   
}

下面是与SimpleImageResizer类一起使用的函数

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);
}

?>
ie3xauqp

ie3xauqp1#

PS:对于单个文件,我使用此脚本,其工作原理:

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>';
    }
    
}

相关问题