ho un sistema per l'upload di immagini, e conseguente ridimensionamento, ma da un un paio di giorni non va. Ho fatto delle modifiche ai file, anche se non avrebbero dovuto riguardare questa parte, ma sfortunatamente le vecchie copie sono state sovrascritte per errore, quindi non posso recuperarle...
Per carcare di capire dov'è il problema, mi sono creato una testimg.php, con solo la funzione di upload. Questo il codice:
Codice PHP:
<?PHP
require "config.php";
include 
"upload.class.php";

$link mysql_connect($host$dbuser$dbpass)
    or die(
"Impossibile connettersi al database");
mysql_select_db($dbname)
    or die(
"Impossibile selezionare il database");
$img $_POST["image"];
echo 
$img;
if (
$img != "") {
$upload = new upload("""400000""newsimg");        
        
$go $upload -> putFile ("image");        
        if ( 
$go ) {    
        
$filePath $upload -> splitFilePath ($go);
        
$img_name $filePath[filename];
        }
        
$mini $upload -> miniatura ($go,"newsimg",100,100,"thumb_");
        if ( 
$mini )  {
            
$filePath $upload -> splitFilePath ($mini);
            
$thmb_name $filePath[filename];
        }
    }
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Documento senza titolo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head><body><form name="add" method="post" action="testimg.php" enctype="multipart/form-data"><input name="image" type="file" id="image" />
<input name="Submit" type="submit" value="  Submit "></form>
</body></html>
quindi provo ad inserire i dati nel db.
Però non inserisce nulla, e l'echo della variabile $img non dà ugualmente nulla!
Questo è il codice del file upload.class.php (che però non ho modificato...):
Codice PHP:
<?php
class upload
{
    var 
$file_permitted;
    var 
$archive_dir;    
    var 
$max_filesize;
    function 
upload $file_perm $max_fil 400000$arc_dir ".." )
    {
        if ( empty (
$file_perm) ) $file_perm = array ("image/pjpeg","image/x-png","image/jpeg","image/png");
        
$this->file_permitted $file_perm;
        
$this->max_filesize $max_fil;
        
$this->archive_dir $arc_dir;
    }
    function 
putFile $file )
    {
        
$userfile_type strtok $_FILES[$file]['type'], ";"); 
        
$userfile_name $_FILES[$file]['name']; 
        
$userfile_size $_FILES[$file]['size']; 
        
$userfile $_FILES[$file]['tmp_name'];  
        
$error "This file type is not permitted: $userfile_type
"
;         
        
$file_permitted $this->file_permitted;
        foreach ( 
$file_permitted as $permitted )
        {
            if ( 
$userfile_type == $permitted $error "";
        }
        if ( (
$userfile_size <= 0) || ($userfile_size $this->max_filesize) ) $error "File size error: $userfile_size Kb.
"
;
        if ( 
$error == "" )
        {
            
$filename basename ($userfile_name); 
            if (!empty (
$this->archive_dir) ) 
                
$destination $this->archive_dir."/".$filename
            else 
                
$destination $filename
            if ( 
file_exists($destination) )
            {
                
srand((double)microtime()*1000000); 
                
$filename rand(0,20000).$filename
                if (!empty (
$this->archive_dir) ) 
                    
$destination $this->archive_dir."/".$filename
                else 
                    
$destination $filename
            }
            if(!
is_uploaded_file($userfile)) die ("File $userfile_name is not uploaded correctly.");
            if ( !@
move_uploaded_file ($userfile,$destination) ) die ("Impossible to copy $userfile_name from $userfile to destination directory.");
            return 
$destination
        }
        else
        {
        
//    echo $error;
            
return false;
        }
    }
    function 
chkgd2()
    {
        
$testGD get_extension_funcs("gd"); 
        if (!
$testGD
        { 
            echo 
"GD not even installed."
            return 
false
        }
        else
        {
            
ob_start(); 
            
phpinfo(8); 
            
$grab ob_get_contents(); 
            
ob_end_clean(); 
            
            
$version strpos  ($grab,"2.0 or higher"); 
            if ( 
$version ) return "gd2"
            else return 
"gd"
        }
    }
    function 
resize_jpeg$image_file_path$new_image_file_path$max_width=500$max_height=500 )
    {
        
$return_val 1;
        if(
eregi("\.png$",$image_file_path)) 
        {
            
$return_val = ( ($img ImageCreateFromPNG $image_file_path )) && $return_val == ) ? "1" "0";
        }
        if(
eregi("\.(jpg|jpeg)$",$image_file_path)) 
        {
            
$return_val = ( ($img ImageCreateFromJPEG $image_file_path )) && $return_val == ) ? "1" "0";
        }
        
$FullImage_width imagesx ($img);
        
$FullImage_height imagesy ($img);
        
$ratio =  ( $FullImage_width $max_width ) ? (real)($max_width $FullImage_width) : ;
        
$new_width = ((int)($FullImage_width $ratio));    
        
$new_height = ((int)($FullImage_height $ratio)); 
        
$ratio =  ( $new_height $max_height ) ? (real)($max_height $new_height) : ;
        
$new_width = ((int)($new_width $ratio));    
        
$new_height = ((int)($new_height $ratio));  
        if ( 
$new_width == $FullImage_width && $new_height == $FullImage_height copy $image_file_path$new_image_file_path );
        
$gd_version = ( $this->chkgd2() );
        if ( 
$gd_version == "gd2" 
        {        
            
$full_id =  ImageCreateTrueColor $new_width $new_height ); 
            
ImageCopyResampled $full_id$img0,0,0,0$new_width$new_height$FullImage_width$FullImage_height );
        }
        elseif ( 
$gd_version == "gd" )
        {        
            
$full_id ImageCreate $new_width $new_height ); 
            
ImageCopyResized $full_id$img0,0,0,0$new_width$new_height$FullImage_width$FullImage_height );
        }
        else 
"GD Image Library is not installed.";
        if(
eregi("\.(jpg|jpeg)$",$image_file_path))
        {
            
$return_val = ( $full ImageJPEG$full_id$new_image_file_path80 ) && $return_val == ) ? "1" "0";
        }
        if(
eregi("\.png$",$image_file_path))
        {
            
$return_val = ( $full ImagePNG$full_id$new_image_file_path ) && $return_val == ) ? "1" "0";
        }
        
ImageDestroy$full_id );
        return (
$return_val) ? TRUE FALSE ;
    }
    function 
miniatura $image_path$path$larghezza=100$altezza=100$pre_name="thumb_" )
    {
        if ( (
eregi("\.png$"$image_path) || eregi("\.(jpg|jpeg)$"$image_path)) && $image_path )
        {
            
$image_name basename $image_path );
            
            if (!empty (
$path) ) 
                
$thumb_path $path."/".$pre_name.$image_name
            else 
                
$thumb_path $pre_name.$image_name
            if ( 
$this->resize_jpeg($image_path$thumb_path$larghezza$altezza) ) return $thumb_path;
            else return 
"Error in thumbnail creation
"
;
        }
        elseif (
$image_path) return "Impossible to create thumbnail by this kind of file
"
;
        elseif (
$send && $image_path) return "<font face=\"Verdana\" size=\"2\" color=\"red\">[b]Error in loading of image $cont[/b]</font>
"
;    
    }
    function 
splitFilePath $completePath "null/null" ) {
        
$filePath = array ( path=>""filename=>"" ) ;
        
$tok strtok($completePath,"/");
        while (
$tok) {
            
$file_name $tok;
            
$tok strtok("/");
        }
        
$path str_replace $file_name""$completePath );
        
$filePath[path] = $path
        
$filePath[filename] = $file_name
        return 
$filePath;
    }        
}
?>
Da cosa può dipendere?