Foros del Web » Programando para Internet » PHP »

subida de archivos php

Estas en el tema de subida de archivos php en el foro de PHP en Foros del Web. Hola buenas, os explico, tengo un problema a la hora de ejecutar una "aplicación" php en MAC de forma local usando xampp como servidor php/mysql. ...
  #1 (permalink)  
Antiguo 09/03/2012, 08:19
 
Fecha de Ingreso: marzo-2011
Mensajes: 53
Antigüedad: 13 años, 1 mes
Puntos: 0
subida de archivos php

Hola buenas,
os explico, tengo un problema a la hora de ejecutar una "aplicación" php en MAC de forma local usando xampp como servidor php/mysql.

La aplicación solo consiste en subir un archivo .txt del ordenador a una carpeta. en pc funciona perfectamente y sube el archivo sin problemas pero en mac no y la verdad que después de darle muchísimas vueltas no se de que puede ser.
Decir también que en el servidor remoto funciona perfectamente, el único sitio donde no funciona es trabajando de forma local en mac.
os dejo el código para que veáis.

Aqui el html completo:
Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    	<title>Adjuntar fichero</title>
        <link href="css/estilos.css" rel="stylesheet" type="text/css" media="screen" />
    	<script src="jquery/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    	<script src="jquery/jquery.uniform.min.js" type="text/javascript" charset="utf-8"></script>
    </head>
    <body>
        <div id="contenedora">
            <h1>Adjuntar fichero</h1>
            <p>Para adjuntar un fichero y enviarlo al servidor debes hacer clic en el botón examinar que se encuentra junto al campo.</p>
            <form action="includes/funciones.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
                <div class="fila-formulario">
                    <label for="fichero">Adjuntar fichero</label>
                    <input name="fichero" type="file" id="fichero" size="40" />
                </div>
                <input type="submit" name="button" id="button" value="Subir fichero" />
            </form>
        </div>
		<script type="text/javascript" charset="utf-8">
          $(function(){
            $("input").uniform();
          });
        </script>
    </body>
</html>

aquí funciones.php
Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    	<title>Confirmación subida de fichero</title>
    	<link href="../css/estilos.css" rel="stylesheet" type="text/css" media="screen" />
    </head>
    <body>
        <div id="contenedora">
            <?php
            $archivo_nombre = $_FILES["fichero"]["name"];
            $archivo_tmp = $_FILES["fichero"]["tmp_name"];
            $archivo_tipo = $_FILES["fichero"]["type"];
            $archivo_peso = $_FILES["fichero"]["size"];
            if($archivo_tipo == "text/plain" && $archivo_peso < 500000){
                if(copy($archivo_tmp,"../archivos-adjuntos/".$archivo_nombre)){
                    echo "El fichero <strong>$archivo_nombre</strong> se ha subido al servidor";
                    unlink($archivo_tmp);
                }else{
                    echo "NO se ha podido realizar la acción.";
                }
            }else{
                echo "Tiene que adjuntar algún fichero cuyo peso no supere 2MB.";
            }
            ?>
            <div class="volver">
            	<a href="../index.html" title="Volver" target="_self">Volver</a>
            </div>
        </div>
    </body>
</html>
espero que alguien me pueda ayudar porque estoy amargado ya :(

Un saludo y muchísimas gracias por adelantado :P
  #2 (permalink)  
Antiguo 09/03/2012, 08:25
 
Fecha de Ingreso: marzo-2011
Mensajes: 53
Antigüedad: 13 años, 1 mes
Puntos: 0
Respuesta: subida de archivos php

Perdon se me olvido poner el error que me suelta cada vez que lo ejecuto en mac, lo unico que sale es Tiene que adjuntar algún fichero cuyo peso no supere 2MB. aunque le suba un fichero de texto vacio, he comprobado el tema de permisos de la carpeta y nada de nada..
saludos!
  #3 (permalink)  
Antiguo 10/03/2012, 06:35
 
Fecha de Ingreso: marzo-2011
Mensajes: 53
Antigüedad: 13 años, 1 mes
Puntos: 0
Respuesta: subida de archivos php

A nadie se le ocurre el porque puede ser? :(
saludos!
  #4 (permalink)  
Antiguo 10/03/2012, 06:56
Avatar de Etherman  
Fecha de Ingreso: abril-2011
Mensajes: 93
Antigüedad: 13 años
Puntos: 2
Respuesta: subida de archivos php

Xampp cambia mucho de Windows a Mac.
No funciona igual, a eso me refiero. Las librerías son muy diferentes como es lógico.
Podría tratarse de alguna restricción de seguridad en macos, o el explorador..
  #5 (permalink)  
Antiguo 10/03/2012, 06:57
Avatar de Etherman  
Fecha de Ingreso: abril-2011
Mensajes: 93
Antigüedad: 13 años
Puntos: 2
Respuesta: subida de archivos php

Prueba otro form diferente a ver que hace...
  #6 (permalink)  
Antiguo 10/03/2012, 09:16
 
Fecha de Ingreso: marzo-2011
Mensajes: 53
Antigüedad: 13 años, 1 mes
Puntos: 0
Respuesta: subida de archivos php

Buenas etherman ante todo muchas gracias por contestar :).
He probado con otro formulario y nada sigue lanzando en error, he pensado en una cosa.. no sera que en mac el nombre de los archivos temporales cambia y por eso de el fallo?
Un saludo y muchas gracias de nuevo :)
  #7 (permalink)  
Antiguo 10/03/2012, 09:40
Avatar de Etherman  
Fecha de Ingreso: abril-2011
Mensajes: 93
Antigüedad: 13 años
Puntos: 2
Respuesta: subida de archivos php

Hola, no te sé responder, pero probablemente puede darte una referencia para saber si funciona, el formulario en el que estoy trabajando. Es un php muy sencillo para subir una imagen, y en el mismo directorio donde se encuentre, hay que tener una carpeta llamada images (donde aparecerá la imagen que estas subiendo.)

Código PHP:
Ver original
  1. <form name="newad" method="post" enctype="multipart/form-data"  action="">
  2.  <table>
  3.     <tr><td><input type="file" name="image"></td></tr>
  4.     <tr><td><input name="Submit" type="submit" value="Upload image"></td></tr>
  5.  </table>  
  6.  </form>
  7.  
  8. <?php
  9. //define a maxim size for the uploaded images in Kb
  10.  define ("MAX_SIZE","100");
  11.  
  12. //This function reads the extension of the file. It is used to determine if the file  is an image by checking the extension.
  13.  function getExtension($str) {
  14.          $i = strrpos($str,".");
  15.          if (!$i) { return ""; }
  16.          $l = strlen($str) - $i;
  17.          $ext = substr($str,$i+1,$l);
  18.          return $ext;
  19.  }
  20.  
  21. //This variable is used as a flag. The value is initialized with 0 (meaning no error  found)  
  22. //and it will be changed to 1 if an errro occures.  
  23. //If the error occures the file will not be uploaded.
  24.  $errors=0;
  25. //checks if the form has been submitted
  26.  if(isset($_POST['Submit']))
  27.  {
  28.     //reads the name of the file the user submitted for uploading
  29.     $image=$_FILES['image']['name'];
  30.     //if it is not empty
  31.     if ($image)
  32.     {
  33.     //get the original name of the file from the clients machine
  34.         $filename = stripslashes($_FILES['image']['name']);
  35.     //get the extension of the file in a lower case format
  36.         $extension = getExtension($filename);
  37.         $extension = strtolower($extension);
  38.     //if it is not a known extension, we will suppose it is an error and will not  upload the file,  
  39.     //otherwise we will do more tests
  40.  if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
  41.         {
  42.         //print error message
  43.             echo '<h1>Unknown extension!</h1>';
  44.             $errors=1;
  45.         }
  46.         else
  47.         {
  48. //get the size of the image in bytes
  49.  //$_FILES['image']['tmp_name'] is the temporary filename of the file
  50.  //in which the uploaded file was stored on the server
  51.  $size=filesize($_FILES['image']['tmp_name']);
  52.  
  53. //compare the size with the maxim size we defined and print error if bigger
  54. if ($size > MAX_SIZE*1024)
  55. {
  56.     echo '<h1>You have exceeded the size limit!</h1>';
  57.     $errors=1;
  58. }
  59.  
  60. //we will give an unique name, for example the time in unix time format
  61. $image_name=time().'.'.$extension;
  62. //the new name will be containing the full path where will be stored (images folder)
  63. $newname="images/".$image_name;
  64. //we verify if the image has been uploaded, and print error instead
  65. $copied = copy($_FILES['image']['tmp_name'], $newname);
  66. if (!$copied)
  67. {
  68.     echo '<h1>Copy unsuccessfull!</h1>';
  69.     $errors=1;
  70. }}}}
  71.  
  72. //If no errors registred, print the success message
  73.  if(isset($_POST['Submit']) && !$errors)
  74.  {
  75.     echo "<h1>File Uploaded Successfully! Try again!</h1>";
  76.  }
  77.  
  78.  ?>
  79.  
  80.  <!--next comes the form, you must set the enctype to "multipart/frm-data" and use an input type "file" -->
  #8 (permalink)  
Antiguo 10/03/2012, 14:06
Avatar de xxxivanxxx  
Fecha de Ingreso: julio-2010
Ubicación: /home
Mensajes: 114
Antigüedad: 13 años, 8 meses
Puntos: 21
Respuesta: subida de archivos php

hola, bueno podria ser que en MAC no estan activos los permisos de escritura sobre el directorio donde intentas subir el archivo.

Etiquetas: formulario, html, sql, subida
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 01:52.