Foros del Web » Programando para Internet » PHP »

Crear upload Asi...

Estas en el tema de Crear upload Asi... en el foro de PHP en Foros del Web. Hola , BUeno les comento que tengo un upload de imagen ... lo cual yo lo modifice y hice lo siguiente... El upload es asi: ...
  #1 (permalink)  
Antiguo 25/01/2009, 20:58
 
Fecha de Ingreso: enero-2007
Mensajes: 56
Antigüedad: 17 años, 3 meses
Puntos: 0
Crear upload Asi...

Hola , BUeno les comento que tengo un upload de imagen ... lo cual yo lo modifice y hice lo siguiente...
El upload es asi:

EL Codigo es este:
Código PHP:
<?php
ini_set
('memory_limit''64M');
  
# DETAILS
  
$UPLOAD_DIR $_POST['carpetas'];    # UPLOAD DIRECTORY
  
$max_width  '650';            # WIDTH TO RESIZE IMAGES ABOVE IT
  
$max_height '500';            # HEIGHT TO RESIZE IMAGES ABOVE IT
   
  # DETECT UPLOAD PRESS
  
if(isset($_POST['upload'])){
    
# ADD HERE THE CODE FOR ANY OTHER FIELDS YOU MIGHT HAVE
     
    # GET UPLOADED FILES
    
$photo $HTTP_POST_FILES['photo'];
    foreach(
$photo['name'] as $file_id => $file){
      
# IF FILE IS IMAGE
      
if($file != NULL && (strstr($file'.jpg') || strstr($file'.png') || strstr($file'.gif'))){
        
# REPLACE QUOTES
        
$file str_replace("'""`"$file);
        
$file str_replace('"''`'$file);
        
# COMPOSE URL
        
$url $UPLOAD_DIR.$file;
        
# COPY FILE TO URL
        
if(copy($photo['tmp_name'][$file_id],$url)){
          
# DELETE TMP FILE
          
unlink($photo['tmp_name'][$file_id]);
          
# GET IMAGE DETAILS
          
$data GetImageSize($url);
          
$mime $data['mime'];
          
# IF IMAGE IS BIGGER THEN MAX VALUES
          
if (($data[0] > $max_width) or ($height $max_height)) {
            
# IF WIDTH IS BIGGER
            
if ($data[0] > $max_width) {
              
$width 5000000;
              
$height 5000000;
            }
            
# IF HEIGHT IS BIGGER AFTER WIDTH BASED RESIZE
            
if ($height $max_height) {
              
$height $max_height;
              
$width $data[0]/($data[1]/$height);
            }
            
# CRATE NEW IMAGE
            
$frame ImageCreateTrueColor($width$height);
            
# CRATE FILE IMAGE
            
if ($mime == 'image/gif') {
              
$im ImageCreateFromGIF($url);
            } else if (
$mime == 'image/png') {
              
$im ImageCreateFromPNG($url);
            } else if (
$mime == 'image/jpeg') {
              
$im ImageCreateFromJPEG($url);
            }
            
# RESIZE
            
imagecopyresized ($frame$im0000$width$height$data[0], $data[1]);
            
# WRITE RESIZED IMAGE
            
imagejpeg($frame,$url,80);
            
imagedestroy($frame);
            
imagedestroy($im);
             
            
# ADD HERE THE CODE THAT INSERTS DATA INTO A DATABASE IF YOU WISH
            # FILE NAME VARIABLE IS  $file
          
}
        }
      }
    }
  }
?>
<form action='' method='post' enctype='multipart/form-data'>
  <p>PHOTO 1: 
    <input type=file name=photo[]>
    <br>
PHOTO 2: 
<input type=file name=photo[]>
<br>
PHOTO 3: 
<input type=file name=photo[]>
<br>
PHOTO 4: 
<input type=file name=photo[]>
<br>
PHOTO 5: 
<input type=file name=photo[]>
  </p>
  <p>Carpeta : 
     <label for="textfield"></label>
     <input name="carpetas" type="text" id="carpetas" value="Dia Del Amigo/" />
  Usar la Barra Al final &quot;/&quot; </p>
  <p>&nbsp;</p>
  <p>
<input type=submit name=upload value=Upload>
</form>
<form id="form1" name="form1" method="post" action="crear1.php">
  <label for="textarea"></label>
  <label for="textarea"></label>
  <label for="textfield"></label>
  <p>Nombre de Carpeta:
    <input type="text" name="carpeta" id="carpeta" />
  </p>
  <p>
    <label for="Submit"></label>
    <input type="submit" name="Submit" value="Crear Carpeta" id="Submit" />
  </p>
</form>
Se usa asi: 1)Examino las fotos que quiero subir . 2) En Carpeta: escribo el nombre de la carpeta donde quiero subir la foto. 3) Donde dice nombre de carpeta es para crear una carpeta nueva.

Yo quiero que en Carpeta: aparezca un menu desplegable con los nombres de las carpetas que estan creada en dicho directorio.
y Segundo: Cuando yo no creo ninguna carpeta me aparece un error ... pero las cosas se suben igual. Quisiera evitar que ese error no Aparezca.

Este es el codigo de crear.php
Código PHP:
<?php
ini_set
('memory_limit''64M');
  
# DETAILS
  
$UPLOAD_DIR $_POST['carpetas'];    # UPLOAD DIRECTORY
  
$max_width  '650';            # WIDTH TO RESIZE IMAGES ABOVE IT
  
$max_height '500';            # HEIGHT TO RESIZE IMAGES ABOVE IT
   
  # DETECT UPLOAD PRESS
  
if(isset($_POST['upload'])){
    
# ADD HERE THE CODE FOR ANY OTHER FIELDS YOU MIGHT HAVE
     
    # GET UPLOADED FILES
    
$photo $HTTP_POST_FILES['photo'];
    foreach(
$photo['name'] as $file_id => $file){
      
# IF FILE IS IMAGE
      
if($file != NULL && (strstr($file'.jpg') || strstr($file'.png') || strstr($file'.gif'))){
        
# REPLACE QUOTES
        
$file str_replace("'""`"$file);
        
$file str_replace('"''`'$file);
        
# COMPOSE URL
        
$url $UPLOAD_DIR.$file;
        
# COPY FILE TO URL
        
if(copy($photo['tmp_name'][$file_id],$url)){
          
# DELETE TMP FILE
          
unlink($photo['tmp_name'][$file_id]);
          
# GET IMAGE DETAILS
          
$data GetImageSize($url);
          
$mime $data['mime'];
          
# IF IMAGE IS BIGGER THEN MAX VALUES
          
if (($data[0] > $max_width) or ($height $max_height)) {
            
# IF WIDTH IS BIGGER
            
if ($data[0] > $max_width) {
              
$width 5000000;
              
$height 5000000;
            }
            
# IF HEIGHT IS BIGGER AFTER WIDTH BASED RESIZE
            
if ($height $max_height) {
              
$height $max_height;
              
$width $data[0]/($data[1]/$height);
            }
            
# CRATE NEW IMAGE
            
$frame ImageCreateTrueColor($width$height);
            
# CRATE FILE IMAGE
            
if ($mime == 'image/gif') {
              
$im ImageCreateFromGIF($url);
            } else if (
$mime == 'image/png') {
              
$im ImageCreateFromPNG($url);
            } else if (
$mime == 'image/jpeg') {
              
$im ImageCreateFromJPEG($url);
            }
            
# RESIZE
            
imagecopyresized ($frame$im0000$width$height$data[0], $data[1]);
            
# WRITE RESIZED IMAGE
            
imagejpeg($frame,$url,80);
            
imagedestroy($frame);
            
imagedestroy($im);
             
            
# ADD HERE THE CODE THAT INSERTS DATA INTO A DATABASE IF YOU WISH
            # FILE NAME VARIABLE IS  $file
          
}
        }
      }
    }
  }
?>
<form action='' method='post' enctype='multipart/form-data'>
  <p>PHOTO 1: 
    <input type=file name=photo[]>
    <br>
PHOTO 2: 
<input type=file name=photo[]>
<br>
PHOTO 3: 
<input type=file name=photo[]>
<br>
PHOTO 4: 
<input type=file name=photo[]>
<br>
PHOTO 5: 
<input type=file name=photo[]>
  </p>
  <p>Carpeta : 
     <label for="textfield"></label>
     <input name="carpetas" type="text" id="carpetas" value="Dia Del Amigo/" />
  Usar la Barra Al final &quot;/&quot; </p>
  <p>&nbsp;</p>
  <p>
<input type=submit name=upload value=Upload>
</form>
<form id="form1" name="form1" method="post" action="crear1.php">
  <label for="textarea"></label>
  <label for="textarea"></label>
  <label for="textfield"></label>
  <p>Nombre de Carpeta:
    <input type="text" name="carpeta" id="carpeta" />
  </p>
  <p>
    <label for="Submit"></label>
    <input type="submit" name="Submit" value="Crear Carpeta" id="Submit" />
  </p>
</form>
<p>&nbsp;<?
$carpeta 
$_POST['carpeta'];
mkdir("$carpeta");  //recomedado
mkdir("$carpeta/thumbnails");  //recomedado 
echo "Su Carpeta se Ah Creado Con Exito"
?></p>
  #2 (permalink)  
Antiguo 26/01/2009, 04:01
 
Fecha de Ingreso: octubre-2004
Mensajes: 2.627
Antigüedad: 19 años, 5 meses
Puntos: 48
Respuesta: [AYUDA] Crear upload Asi...

www.php.net/opendir
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 12:28.