Foros del Web » Programando para Internet » PHP »

File not writable en PHP

Estas en el tema de File not writable en PHP en el foro de PHP en Foros del Web. En servidor local, no tengo drama con subir archivos. En el servidor 000webhost me sale este error. Sin embargo, con otros scripts no he tenido ...
  #1 (permalink)  
Antiguo 02/03/2010, 15:39
Avatar de mayid
Colaborador
 
Fecha de Ingreso: marzo-2009
Ubicación: BsAs
Mensajes: 4.014
Antigüedad: 15 años, 1 mes
Puntos: 101
File not writable en PHP

En servidor local, no tengo drama con subir archivos. En el servidor 000webhost me sale este error. Sin embargo, con otros scripts no he tenido problemas al subir material. Que será?

Tengo los permisos en 777.

Cita:
Fatal error: Uncaught exception 'RuntimeException' with message 'File not writeable: /usr/local/apache/htdocs/MeshRepository/album/Characters/horse_mayid.jpg' in /home/a6118506/public_html/MeshRepository/libreria/miniaturas/GdThumb.inc.php:626 Stack trace: #0 /home/a6118506/public_html/MeshRepository/libreria/script.php(78): GdThumb->save('/usr/local/apac...') #1 {main} thrown in /home/a6118506/public_html/MeshRepository/libreria/miniaturas/GdThumb.inc.php on line 626
  #2 (permalink)  
Antiguo 02/03/2010, 15:42
Avatar de mayid
Colaborador
 
Fecha de Ingreso: marzo-2009
Ubicación: BsAs
Mensajes: 4.014
Antigüedad: 15 años, 1 mes
Puntos: 101
Respuesta: File not writable en PHP

Rutas absolutas. Claramente. Estaba usando esto:



$raiz = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'];

y cambie la variable por "..". Ahora funciona.

Pero todavia tengo otro error, tanto en local como en 000webhost.

Cita:
Fatal error: Uncaught exception 'RuntimeException' with message 'File not writeable: ../MeshRepository/album/Characters/horse_mayid.jpg' in /home/a6118506/public_html/MeshRepository/libreria/miniaturas/GdThumb.inc.php:626 Stack trace: #0 /home/a6118506/public_html/MeshRepository/libreria/script.php(75): GdThumb->save('../MeshReposit...') #1 {main} thrown in /home/a6118506/public_html/MeshRepository/libreria/miniaturas/GdThumb.inc.php on line 626
Cita:
Warning: move_uploaded_file(../MeshRepository/album/Characters/aeer_abress.aoi) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\wamp\www\MeshRepository\libreria\script.php on line 81

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\wamp\tmp\phpCD9.tmp' to '../MeshRepository/album/Characters/aeer_abress.aoi' in C:\wamp\www\MeshRepository\libreria\script.php on line 81
Error when saving the file!

Última edición por mayid; 02/03/2010 a las 15:48
  #3 (permalink)  
Antiguo 02/03/2010, 15:43
Avatar de darkasecas  
Fecha de Ingreso: marzo-2005
Ubicación: SantaCata, NL, Mexico
Mensajes: 1.553
Antigüedad: 19 años, 1 mes
Puntos: 77
Respuesta: File not writable en PHP

Estas intentando subir un archivo a /usr/local/apache/htdocs/MeshRepository/album/Characters/... seguro que es correcta esa ruta?
  #4 (permalink)  
Antiguo 02/03/2010, 15:44
Avatar de darkasecas  
Fecha de Ingreso: marzo-2005
Ubicación: SantaCata, NL, Mexico
Mensajes: 1.553
Antigüedad: 19 años, 1 mes
Puntos: 77
Respuesta: File not writable en PHP

Bueno, ahora la ruta dice ..//MeshRepository, prueba sacandole un /
  #5 (permalink)  
Antiguo 02/03/2010, 15:50
Avatar de mayid
Colaborador
 
Fecha de Ingreso: marzo-2009
Ubicación: BsAs
Mensajes: 4.014
Antigüedad: 15 años, 1 mes
Puntos: 101
Respuesta: File not writable en PHP

Cita:
Bueno, ahora la ruta dice ..//MeshRepository, prueba sacandole un /
Cierto, gracias. AHi lo corregi, pero el error sigue. Son dos errores: uno para una foto, otro para un archivo.

Cita:
Fatal error: Uncaught exception 'RuntimeException' with message 'File not writeable: ../MeshRepository/album/Characters/aeer_abress.jpg' in C:\wamp\www\MeshRepository\libreria\miniaturas\GdT humb.inc.php:626 Stack trace: #0 C:\wamp\www\MeshRepository\libreria\script.php(75) : GdThumb->save('../MeshReposito...') #1 {main} thrown in C:\wamp\www\MeshRepository\libreria\miniaturas\GdT humb.inc.php on line 626

Error uploading file.

Warning: move_uploaded_file(../MeshRepository/album/Characters/aeer_abress.aoi) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\wamp\www\MeshRepository\libreria\script.php on line 81

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\wamp\tmp\phpCD9.tmp' to '../MeshRepository/album/Characters/aeer_abress.aoi' in C:\wamp\www\MeshRepository\libreria\script.php on line 81
Error when saving the file!
  #6 (permalink)  
Antiguo 02/03/2010, 16:01
Avatar de mayid
Colaborador
 
Fecha de Ingreso: marzo-2009
Ubicación: BsAs
Mensajes: 4.014
Antigüedad: 15 años, 1 mes
Puntos: 101
Respuesta: File not writable en PHP

Evidentemente el causante es esta linea.

$raiz = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'];

$raiz = ".." . $_GET['folder'];

Escrita de la primera manera, todo va bien en servidor local. Escrita de la otra, salta error.

El resto del codigo es este:
Código PHP:
if ($extension == "jpg" or $extension == "jpeg" or $extension == "gif" or $extension == "png" or $extension == "JPG" )
 {
// hago la miniatura
// ***********************************  //
require_once 'miniaturas/ThumbLib.inc.php';
        
// cambio el tamaño, poniendo maximos w & h
        
$options = array('jpegQuality' => 80);
        
        
$temporal $_FILES['Filedata']['tmp_name'];
        
$temporal urldecode($temporal);
        
        try
        {
             
$img PhpThumbFactory::create($temporal$options);
             
$thumb PhpThumbFactory::create($temporal$options);
        }
        catch (
Exception $e)
        {
             
// handle error here however you'd like
             
$error 'Error scaling the image.';
        }
        

// guarda la foto temporal        
// ***********************************  //
 
$img->resize(800,650)->save($raiz $nuevo_nombre);
 
$thumb->adaptiveResize(90,90)->save($raiz ."_thumb_".$nuevo_nombre);
}

elseif (
$extension == "aoi" or $extension == "zip" or $extension == "rar" or $extension == "g7"){
     
// manejo de errores
     
if (move_uploaded_file($_FILES['Filedata']['tmp_name'], $raiz.$nuevo_nombre)){
     }     else{
     
$error 'Error when saving the file!';
     }
}; 
  #7 (permalink)  
Antiguo 02/03/2010, 16:13
Avatar de mayid
Colaborador
 
Fecha de Ingreso: marzo-2009
Ubicación: BsAs
Mensajes: 4.014
Antigüedad: 15 años, 1 mes
Puntos: 101
Respuesta: File not writable en PHP

Cita:
$raiz = ".." . $_GET['folder'];
Me di cuenta de dos cosas. Estoy usando ajax, por lo tanto no necesito la ruta "..". Por otro lado, que sobra una carpeta en la ruta. La primera. Y estoy tratando de eliminarla.

Cita:
$raiz = $_GET['folder'];
Cita:
MeshRepository/album/Characters/aeer_abress.aoi
Cita:
$array_raiz = explode("/",$_GET['folder']);
$residuo = array_shift($array_raiz);
$raiz = implode("/",$array_raiz);
Pero sigue igual. La primera carpeta persiste! No se borra con arary_shift, aparentemente.
  #8 (permalink)  
Antiguo 02/03/2010, 16:22
Avatar de mayid
Colaborador
 
Fecha de Ingreso: marzo-2009
Ubicación: BsAs
Mensajes: 4.014
Antigüedad: 15 años, 1 mes
Puntos: 101
Respuesta: File not writable en PHP

Esto ya es comico, porque es como un dialogo interno, pero bueno. Quito la primera carpeta así, aunque no sea lo mejor:

Cita:
$raiz = str_replace("MeshRepository/", "", $_GET['folder']);
Y sigue habiendo un error! Y una barrita delante de $raiz que no se de donde sale.

Cita:
Fatal error: Uncaught exception 'RuntimeException' with message 'File not writeable: /album/Characters/htrh_acfre.jpg' in C:\wamp\www\MeshRepository\libreria\miniaturas\GdT humb.inc.php:626 Stack trace: #0 C:\wamp\www\MeshRepository\libreria\script.php(74) : GdThumb->save('/album/Characte...') #1 {main} thrown in C:\wamp\www\MeshRepository\libreria\miniaturas\GdT humb.inc.php on line 626
  #9 (permalink)  
Antiguo 02/03/2010, 16:31
Avatar de mayid
Colaborador
 
Fecha de Ingreso: marzo-2009
Ubicación: BsAs
Mensajes: 4.014
Antigüedad: 15 años, 1 mes
Puntos: 101
Respuesta: File not writable en PHP

Rarisimo. Elimine esta subcadena "/MeshRepository/", que por cierto no se por qué se agrega a mi ruta. Y agregué "../" en su lugar. Y funciona. No entiendo por què.

Cita:
$raiz = str_replace("/MeshRepository/", "", $_GET['folder']);
$raiz = "../".$raiz;
Este problema va mas allá de rutas relativas y absolutas. No lo entiendo. Pero al menos logré solucionarlo.

Etiquetas: file
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:18.