Ver Mensaje Individual
  #2 (permalink)  
Antiguo 24/05/2009, 21:31
Avatar de abimaelrc
abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 15 años
Puntos: 1517
Respuesta: Carro de compras con fotos de articulos

Saludos:

No es recomendable pasar una foto a una base de datos. Lo recomendable es pasar un link donde se encuentra la foto en el servidor.

Cargas la foto al servidor y la información que tiene la foto la colocas luego en la base de datos ejemplo. Te voy a dar un codigo que yo cree, pero sin editar, tu has los arreglos pertinentes en el.

Código HTML:
<form name="addPict" action="WRITE_HERE_THE_PHP_FILE" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="2048000">
<input type="file" name="srcImg" size="60">
<input type="submit" value="submit">
</form> 

Código PHP:
    if(isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH']>2097152){
        
$action $action.'&whatType=PROFILE&error=Upload FAILED, file is too large!';
        
header("Location: $action");
        die();
    }
    
    if(
$srcImg_type == "image/x-png"
        
|| $srcImg_type == "image/png" 
        
|| $srcImg_type == "image/gif" 
        
|| $srcImg_type == "image/gif" 
        
|| $srcImg_type == "image/pjpeg"
        
|| $srcImg_type == "image/jpeg"){
    }else{
        
$action $action.'&whatType=PROFILE&error=Upload FAILED, is not a jpg, gif or png file!';
        
header("Location: $action");
        die();
    }

    
$txtname strtolower(basename($srcImg));
    
$getExplName explode("."$txtname);
    
$txtname $_COOKIE["ID_Cookie"] . "." $getExplName[1];

    
$result = @move_uploaded_file($srcImg_tmp$txtname);

    if(!
file_exists($root_dir)){
        
mkdir($root_dir);
        
chmod($root_dir0777);
    }

    if(!
file_exists($root_dir."/".$_COOKIE["ID_Cookie"])){
        
mkdir($root_dir."/".$_COOKIE["ID_Cookie"]);
        
chmod($root_dir."/".$_COOKIE["ID_Cookie"], 0777);
    }

    if(!
file_exists($root_dir."/".$_COOKIE["ID_Cookie"]."/".$profile_pic_dir)){
        
mkdir($root_dir."/".$_COOKIE["ID_Cookie"]."/".$profile_pic_dir);
        
chmod($root_dir."/".$_COOKIE["ID_Cookie"]."/".$profile_pic_dir0777);
    }

    if(!
file_exists($root_dir."/".$_COOKIE["ID_Cookie"]."/".$resize_pic_dir)){
        
mkdir($root_dir."/".$_COOKIE["ID_Cookie"]."/".$resize_pic_dir);
        
chmod($root_dir."/".$_COOKIE["ID_Cookie"]."/".$resize_pic_dir0777);
    }

    
$getProfileFile $root_dir."/".$_COOKIE["ID_Cookie"]."/".$profile_pic_dir."/profile_".$txtname;
    
$getResizeFile $root_dir."/".$_COOKIE["ID_Cookie"]."/".$resize_pic_dir."/".$txtname;

    
$sql_tpp "SELECT * 
        FROM tbl_picture_profile
        WHERE ID_userpass = '"
.$_COOKIE["ID_Cookie"]."'";
    
$r_tpp mysql_query($sql_tpp) or die("Error.");
    
$row_tpp mysql_fetch_assoc($r_tpp);

    if(
is_array($row_tpp)){
        if(
file_exists($row_tpp["profilePict"])){
            
$getBasenameResizeFileR basename($row_tpp["resizePict"]);
            
$getBasenameResizeFileP basename($row_tpp["profilePict"]);
            
copy($row_tpp["resizePict"], $root_dir."/".$_COOKIE["ID_Cookie"]."/".$getBasenameResizeFileR);
            
copy($row_tpp["profilePict"], $root_dir."/".$_COOKIE["ID_Cookie"]."/".$getBasenameResizeFileP);
        }
    }

    list(
$pWidth$pHeight$pType$pAttr) = getimagesize($getResizeFile);

    if(
$pType == 1){
        
$pType "gif";
    }elseif(
$pType == 2){
        
$pType "jpg";
    }elseif(
$pType == 3){
        
$pType "png";
    }

    if(
is_array($row_tpp)){
        if(
$row_tpp["pType"] != $pType){
            @
unlink($row_tpp["resizePict"]);
            @
unlink($row_tpp["profilePict"]);
        }
        
$del_tpp "DELETE FROM tbl_picture_profile 
            WHERE ID = '"
.$row_tpp["ID"]."'";
        
$r_del_tpp mysql_query($del_tpp) or die("Error.");
    }


    
$sql_tpp_rechk "SELECT * 
        FROM tbl_picture_profile
        WHERE ID_userpass = '"
.$_COOKIE["ID_Cookie"]."'";
    
$r_tpp_rechk mysql_query($sql_tpp_rechk) or die("Error.");
    
$row_tpp_rechk mysql_fetch_assoc($r_tpp_rechk);

    if(!
is_array($row_tpp_rechk)){
        
$sql_p "INSERT INTO tbl_picture_profile(
                resizePict,
                pWidth,
                pHeight,
                pType,
                profilePict, 
                Date, 
                ID_userpass
            ) 
            VALUES(
                '$getResizeFile',
                '$pWidth',
                '$pHeight',
                '$pType',
                '$getProfileFile',
                '"
.date("Y-m-d")."',
                '"
.$_COOKIE["ID_Cookie"]."'
            )"
;
        
$result_p mysql_query($sql_p) or die("Error.");
    }

    
$action $action."&whatType=PROFILE&whatTypeSub=CUSTOMPICT&getResizeFile=$getResizeFile&getProfileFile=$getProfileFile&pType=$pType";

    @
unlink($txtname);
    @
unlink($getProfileFile); 

Perdona que no edite es que es mucho el codigo pero creo que es suficiente para lograr lo que quieres, me dejas saber si tienes inconvenientes