Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/04/2011, 04:07
Avatar de jorjo
jorjo
 
Fecha de Ingreso: abril-2007
Ubicación: España
Mensajes: 90
Antigüedad: 17 años
Puntos: 1
Error al subir imagen

Hola PHP-eros!

A ver si me podeis ayudar, tengo un código para subir imágenes desde un formulario que ya me funcionaba en otra web con otro servidor, pero ahora me da error... nose si es cosa del código o del server... pero a mi me parece que todo está bien. Una ayudita por favor.

Aquí el código:
Código PHP:
    //Subimos la imagen...
    
if (($HayError == false) && ($_FILES['userfile']['name'] != '')){
        if (!(
strpos($_FILES['userfile']['type'], "gif") || strpos($_FILES['userfile']['type'], "jpeg") || strpos($_FILES['userfile']['type'], "png"))) {
            
$errorImagen "Sólo se permiten archivos .gif, .jpg o .png";
            
$HayError true;
        }elseif(
$_FILES['userfile']['size'] > 4096000){
            
$errorImagen "Tamaño máximo 4Mb.";
            
$HayError true;
        }else{
            
$archivoimagen AhoraTexto()."_".$_FILES['userfile']['name'];
            if (!(
move_uploaded_file($_FILES['userfile']['tmp_name'], "../images/ocasion/".$archivoimagen))){
                
$errorImagen "No se pudo subir el archivo";
                
$HayError true;
            }else{
                
//Según el tipo...
                
if (strpos($_FILES['userfile']['type'], "gif")){
                    
$fuente = @imagecreatefromgif("../images/ocasion/".$archivoimagen);
                }elseif (
strpos($_FILES['userfile']['type'], "jpeg")){
                    
$fuente = @imagecreatefromjpeg("../images/ocasion/".$archivoimagen);
                }elseif (
strpos($_FILES['userfile']['type'], "png")){
                    
$fuente = @imagecreatefrompng("../images/ocasion/".$archivoimagen);
                }
                                
                if(
$fuente){
                    
$xx imagesx($fuente);
                    
$yy imagesy($fuente);
                    
                    if(
$xx >= $yy){
                        if(
$xx 800){ $x1 800$y1 800*$yy/$xx; }
                        else{ 
$x1 $xx$y1 $yy;    }
                        if(
$xx 200){ $x2 200$y2 200*$yy/$xx; }
                        else{ 
$x2 $xx$y2 $yy; }
                    }elseif(
$xx $yy){
                        if(
$yy 800){ $x1 600*$xx/$yy$y1 600; }
                        else{ 
$x1 $xx$y1 $yy; }
                        if(
$yy 200){ $x2 150*$xx/$yy$y2 150; }
                        else{ 
$x2 $xx$y2 $yy; }
                    }
                    
$imagen imagecreatetruecolor($x1,$y1);
                    
imagecopyresized($imagen,$fuente,0,0,0,0,$x1,$y1,$xx,$yy);
                    
//Según el tipo...
                    
if (strpos($_FILES['userfile']['type'], "gif")){
                        
imagegif($imagen,"../images/ocasion/".$archivoimagen);
                    }elseif (
strpos($_FILES['userfile']['type'], "jpeg")){
                        
imagejpeg($imagen,"../images/ocasion/".$archivoimagen,100);
                    }elseif (
strpos($_FILES['userfile']['type'], "png")){
                        
imagepng($imagen,"../images/ocasion/".$archivoimagen);
                    }
                    
                    
//Hacemos el Thumb...
                    
$imagen imagecreatetruecolor($x2,$y2);
                    
imagecopyresized($imagen,$fuente,0,0,0,0,$x2,$y2,$xx,$yy);
                    
//Según el tipo...
                    
if (strpos($_FILES['userfile']['type'], "gif")){
                        
imagegif($imagen,"../images/ocasion/thumbs/".$archivoimagen);
                    }elseif (
strpos($_FILES['userfile']['type'], "jpeg")){
                        
imagejpeg($imagen,"../images/ocasion/thumbs/".$archivoimagen,100);
                    }elseif (
strpos($_FILES['userfile']['type'], "png")){
                        
imagepng($imagen,"../images/ocasion/thumbs/".$archivoimagen);
                    }
                }else{
                    
$errorImagen "No se ha podido redimensionar la imagen.";
                    
$HayError true;
                }
            }
        }
    } 
El error me lo da en la línea:
Código PHP:
if (!(move_uploaded_file($_FILES['userfile']['tmp_name'], "../images/ocasion/".$archivoimagen))){ 
Parámetros del server:
Código:
Language Options 	asp_tags 	Allow ASP-style <% %> tags. 	Off
File Uploads 	file_uploads 	Whether to allow HTTP file uploads. 	On
Paths and Directories 	include_path 	Windows: "\path1;\path2" c:\php\includes" 	.:/usr/lib/php:/usr/local/lib/php
Resource Limits 	max_execution_time 		30
Resource Limits 	max_input_time 		60
Resource Limits 	memory_limit 		254M
Data Handling 	register_globals 	You should do your best to write your scripts so that they do not require register_globals to be on; Using form variables as globals can easily lead to possible security problems, if the code is not very well thought of. 	On
Language Options 	safe_mode 		Off
main 	session.save_path 	where N is an integer. Instead of storing all the session files in /path, what this will do is use subdirectories N-levels deep, and store the session data in those directories. This is useful if you or your OS have problems with lots of files in one directory, and is a more efficient layout for servers that handle lots of sessions. NOTE 1: PHP will not create this directory structure automatically. You can use the script in the ext/session dir for that purpose. NOTE 2: See the section on garbage collection below if you choose to use subdirectories for session storage 	/tmp
File Uploads 	upload_max_filesize 	Maximum allowed size for uploaded files. 	20M
Saludos y gracias!