Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/01/2010, 19:50
WinderJerter
 
Fecha de Ingreso: agosto-2009
Mensajes: 292
Antigüedad: 14 años, 9 meses
Puntos: 5
subir imagenes desde una url con PHP

Hola que tal, les cuento, ando haciendole unas modificaciones al script de Pato12, entre las modificaciones que ando haciendo unas es poder subir una imagen desde una url externa y que se procese en el archivo upload.php, modificando el type="file" por un type="text" para poner escribir la url.

mi pregunta es: ¿Como podria adaptar el formulario para poder subir imagenes examinandolas desde la Pc y con un link de una iamgen?

Pongo el codigo del index.php que es desde donde se envia la imagen y upload.php que es donde se procesa el archivo enviado mediante post.

index.php
Código HTML:
Ver original
  1. <form action="upload.php" method="post" enctype="multipart/form-data">
  2.     Archivo: <input name="file" id="input-file" type="file" /><br>
  3.    
  4.     <br>
  5.     <input type="checkbox" name="checktitle" id="checkalt" onclick="if(this.checked==false)this.form.addtitle.disabled=true;else this.form.addtitle.disabled=false" />Agregar titulo:
  6.     <input type="text" name="addtitle" id="addtitle" disabled="disabled" /><br>
  7.    
  8.     <br>
  9.     <input type="checkbox" name="checklink" id="checklink" onclick="if(this.checked==false)this.form.addlink.disabled=true;else this.form.addlink.disabled=false" />Agregar vínculo: http://
  10.     <input type="text" name="addlink" id="addlink" disabled="disabled" /><br>
  11.    
  12.     <br>
  13.     Por seguridad, escriba el texto que se muestra en la imagen:<br>
  14.     <input name="tmptxt" type="text" maxlength="8" />
  15.     <img src="captcha.php" id="captcha" vspace="3" />
  16.     <input type="button" id="reload-captcha" title="Recargar captcha" onClick="reloadCaptcha()" /><br>
  17.     <span id="span-captcha">Sensible entre mayúsculas y minúsculas.</span><br>
  18.  
  19.     <br>
  20.     <input name="submit" type="submit" value="Upload!" />
  21.  
  22. </form>

upload.php
Código PHP:
Ver original
  1. <?php
  2. if($_POST)
  3. {
  4.     if($_SESSION[tmptxt] == $_POST[tmptxt])
  5.     {
  6.         $key = "si";
  7.     }
  8.     else
  9.     {
  10.         echo "El codigo antispam esta mal.";
  11.     }
  12. }
  13. if($key == "si")
  14. {
  15.     $str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
  16.     $cad = "";
  17.     for($i = 0; $i < 12; $i ++)
  18.     {
  19.         $cad .= substr($str, rand(0, 62), 1);
  20.     }
  21.     $size = $_FILES[file][size];
  22.     $size_max = "3670016"; //3.5 MB
  23.     if($size < $size_max)
  24.     {
  25.         $destino = "img";
  26.         $sep = explode('image/', $_FILES[file][type]);
  27.         $tipo = $sep[1];
  28.         if($tipo == "png" || $tipo == "x-png" || $tipo == "gif" || $tipo == "jpeg" || $tipo == "pjpeg" || $tipo == "bmp")
  29.         {
  30.             move_uploaded_file($_FILES[file][tmp_name], $destino.'/'.$cad.'.'.$tipo);
  31.             include("post.php");
  32.         }
  33.         else echo "El tipo de imagen no esta permitido.";
  34.     }
  35.     else echo "La imagen supera el peso permitido.";
  36. }
  37. $_SESSION[tmptxt] = microtime();
  38. ?>

Saludos y gracias de antemano

Última edición por WinderJerter; 10/01/2010 a las 14:27