Visualizzazione dei risultati da 1 a 3 su 3

Discussione: upload immagine

  1. #1
    Utente di HTML.it L'avatar di lukezz
    Registrato dal
    Feb 2010
    Messaggi
    494

    upload immagine

    Salve a tutti!
    ho un e-commerce che mi da problemi con l'upload di immagini, sia quando creo una galleria che quando creo un nuovo prodotto, riesce ad inserire tutti i dati nel database tranne il nome della foto e la foto nella cartella di destinazione, ecco il codice:

    Codice PHP:
    function addCategory()
    {
        
    $name        $_POST['txtName'];
        
    $description $_POST['mtxDescription'];
        
    $image       $_FILES['fleImage'];
        
    $parentId    $_POST['hidParentId'];
        
        
    $catImage uploadImage('fleImage'SRV_ROOT '/images/category/');
        
        
    $sql   "INSERT INTO tbl_category (cat_parent_id, cat_name, cat_description, cat_image) 
                  VALUES (
    $parentId, '$name', '$description', '$catImage')";
        
    $result dbQuery($sql) or die('Cannot add category' mysql_error());
        
        
    header('Location: index.php?catId=' $parentId);              
    }

    /*
        Upload an image and return the uploaded image name 
    */
    function uploadImage($inputName$uploadDir)
    {
        
    $image     $_FILES[$inputName];
        
    $imagePath '';
        
        
    // if a file is given
        
    if (trim($image['tmp_name']) != '') {
            
    // get the image extension
            
    $ext substr(strrchr($image['name'], "."), 1); 

            
    // generate a random new file name to avoid name conflict
            
    $imagePath md5(rand() * time()) . ".$ext";
            
            
    // check the image width. if it exceed the maximum
            // width we must resize it
            
    $size getimagesize($image['tmp_name']);
            
            if (
    $size[0] > MAX_CATEGORY_IMAGE_WIDTH) {
                
    $imagePath createThumbnail($image['tmp_name'], $uploadDir $imagePathMAX_CATEGORY_IMAGE_WIDTH);
            } else {
                
    // move the image to category image directory
                // if fail set $imagePath to empty string
                
    if (!move_uploaded_file($image['tmp_name'], $uploadDir $imagePath)) {
                    
    $imagePath '';
                }
            }    
        }

        
        return 
    $imagePath;

    Cosa sbaglio? ho controllato tutto ma niente. (almeno penso)

  2. #2
    Utente di HTML.it L'avatar di homerbit
    Registrato dal
    Dec 2005
    residenza
    Roma
    Messaggi
    1,380
    cosa restituisce $catImage ?
    il percorso img è esatto?
    prova ad eseguire l'upload senza la query
    If you think your users are idiots, only idiots will use it. DropBox

  3. #3
    Utente di HTML.it L'avatar di lukezz
    Registrato dal
    Feb 2010
    Messaggi
    494
    Ho cambiato metodo.

    sto usando copy:

    Codice PHP:
    function addCategory()
    {
        
    $name        $_POST['txtName'];
        
    $description $_POST['mtxDescription'];
        
    //$image       = $_FILES['fleImage'];
        
    $parentId    $_POST['hidParentId'];
        
    $cartella SRV_ROOT .'images/category/';
        
        
        
    $tipi_consentiti = array("image/gif","image/jpeg","image/jpg","image/pjpeg","image/png");
        
        
    //verifico che l'input figura esiste
        
    if (strlen($_FILES['fleImage']['name']) > ) {                               
      
    // verifico che il formato del file sia tra quelli accettati
     
    if (in_array($_FILES['fleImage']['type'], $tipi_consentiti)){
         
    copy ($_FILES['fleImage']['tmp_name'], $cartella $_FILES['fleImage']['name']);
        
    $image addslashes($_FILES['fleImage']['name']);
        
    $path $cartella stripslashes($image);
        
    $tipo addslashes($_FILES['fleImage']['type']);
        
     }else{ 
     
    //errore
     
    echo "file non consentito.";
     }
        }

    $sql   "INSERT INTO tbl_category (cat_parent_id, cat_name, cat_description, cat_image) 
                  VALUES (
    $parentId, '$name', '$description', '$image')";
        
    $result dbQuery($sql) or die('Cannot add category' mysql_error());
        
        
    header('Location: index.php?catId=' $parentId);              

    In questo modo mi inserisce il tutto nel database ma non mi copia nulla sulla cartella di destinazione, come mai? ho già impostato i permessi a 777 e ho definito quel SRV_ROOT cosi: define('SRV_ROOT', '/root/www/');

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.