Visualizzazione dei risultati da 1 a 7 su 7
  1. #1
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560

    Aggiungere variabile stringa di codice

    Buongiorno,

    devo aggiungere
    Codice PHP:
    $targetFilePath 


    in questa riga, dopo $targetFile
    Codice PHP:
    if (move_uploaded_file($tempFile,$targetPath."/".$targetFile)) { 

    Come fare? Chi mi spiega gentilmente?
    Grazie

  2. #2
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    Ho provato così ma non funziona:

    Codice PHP:
    if (move_uploaded_file($tempFile,$targetPath."/".$targetFile.".".$targetFilePath)) { 

  3. #3
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,445
    Cosa c'è in $targetFilePath? Da come lo usi ci dovrebbe essere un'estensione di un file, ma dal nome si direbbe un percorso.

    Invece di fare l'if, stampa la stringa con un echo e vedi cosa ti restituisce, così dovresti capire dove sta l'errore.

  4. #4
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    Si un percorso:
    Codice PHP:
    $targetFilePath $targetDir $fileName
    ho messo echo $targetFilePath; ma nella pagina dopo l'upload non mi restituisce nulla

  5. #5
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,445
    In $targetDir e $fileName che c'è?
    Devi assicurarti che tutte le variabili siano correttamente inizializzate e contengano effettivamente ciò che dovrebbero.

    Se l'echo non stampa nulla le cose sono 2: nella variabile c'è la stringa vuota, oppure sta in un posto dove ciò che stampa non è visibile.

  6. #6
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    Forse facciamo prima così a capire(se ti va di darmi una mano):

    praticamente devo inserire questo codice 1 watermark(funzionante) nel mio codice 2:

    codice 1:
    Codice PHP:
    <?php 
    // Path configuration 
    $targetDir "wp-content/uploads/"
    $watermarkImagePath 'file.png';


    $statusMsg '';
    if(isset(
    $_POST["submit"])){ 
        if(!empty(
    $_FILES["file"]["name"])){ 

    // File upload path        
     
    $fileName basename($_FILES["file"]["name"]);         
    $targetFilePath $targetDir $fileName;         
    $fileType pathinfo($targetFilePath,PATHINFO_EXTENSION);  

    // Allow certain file formats 
            
    $allowTypes = array('jpg','png','jpeg'); 
            if(
    in_array($fileType$allowTypes)){

    // Upload file to the server 
                
    if(move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath)){ 
                    
    // Load the stamp and the photo to apply the watermark to 
                    
    $watermarkImg imagecreatefrompng($watermarkImagePath); 
                    switch(
    $fileType){ 
                        case 
    'jpg'
                            
    $im imagecreatefromjpeg($targetFilePath); 
                            break; 
                        case 
    'jpeg'
                            
    $im imagecreatefromjpeg($targetFilePath);                         
                           break;                     
                       case 
    'png':                         
                            
    $im imagecreatefrompng($targetFilePath); 
                            break; 
                        default: 
                            
    $im imagecreatefromjpeg($targetFilePath); 
                    } 

    // Set the margins for the watermark 
                    
    $marge_right 10
                    
    $marge_bottom 10
                     
                    
    // Get the height/width of the watermark image 
                    
    $sx imagesx($watermarkImg); 
                    
    $sy imagesy($watermarkImg);                                  
    // Copy the watermark image onto our photo using the margin offsets and                  
    // the photo width to calculate the positioning of the watermark. 
                    
    imagecopy($im$watermarkImgimagesx($im) - $sx $marge_rightimagesy($im) - $sy $marge_bottom00imagesx($watermarkImg), imagesy($watermarkImg)); 
                                     
    // Save image and free memory 
                    
    imagepng($im$targetFilePath); 
                    
    imagedestroy($im);
                         if(
    file_exists($targetFilePath)){                     $statusMsg "The image with watermark has been uploaded successfully.";                
     }else{                     
    $statusMsg "Image upload failed, please try again.";                
     }              
    }else{ 
                    
    $statusMsg "Sorry, there was an error uploading your file.";            
     } 
            }else{ 
                
    $statusMsg 'Sorry, only JPG, JPEG, and PNG files are allowed to upload.'
            } 
        }else{ 
            
    $statusMsg 'Please select a file to upload.';
        } 

     
    // Display status message
    echo $statusMsg;

    ?>






    il codice con gli asterischi(*********************) l'ho inserito io:


    codice 2:
    Codice PHP:
    <?php
    ini_set
    'display_errors');


    require( 
    '../../../wp-load.php' );
    ****************************
    $watermarkImagePath 'watermark.png'
    ****************************
    $targetDir "../../uploads/"

    if (!empty(
    $_FILES)) {

    // File upload path         
    *********************$fileName basename($_FILES["file"]["name"]);         
    *********************
    $targetFilePath $targetDir $fileName;        
    *********************
    $fileType pathinfo($targetFilePath,PATHINFO_EXTENSION); 

        
    $secret explode("/"$_REQUEST['folder']);
        
    $secret $secret[(count($secret)-1)];
        
    $secret preg_replace("/([^a-zA-Z0-9])/"""$secret);
        
    //check if an agency added this post
        
    $escort_post_id get_option("agency".$secret);


        if (
    $escort_post_id) {
            
    //this means the article was added by an agency
        
    } elseif (get_option($secret)) {
            
    //this means the article was added by an escort
            
    $escort_user_id get_option($secret);
            
    $escort_post_id get_option("escortpostid".$escort_user_id);
        } else {
            
    //if we don't find a secret added by an agency and neither by an independent escort then we die()

            
    die('We couldn\'t find a profile');
        }


        
    //checking the number of uploaded photos
        
    $photos get_children( array('post_parent' => $escort_post_id'post_status' => 'inherit''post_type' => 'attachment''post_mime_type' => 'image''order' => 'ASC''orderby' => 'menu_order ID') );
        if (
    count($photos) >= get_option('maximgupload')) { die(); }


        
    //Get the Size of the File
        
    $size_bytes get_option('maximguploadsize') * 1024 1024//5MB
        
    $file_size $_FILES['Filedata']['size'];


        
    //Make sure that file size is correct
        
    if ($file_size $size_bytes){ die("The file is too large"); }
        if (
    $file_size == "0"){ die("The file can't have 0Kb"); }




        
    //check file extension
        
    $allowed_extensions = array("gif","png","jpg","jpeg");
        
    $image_mime_type getimagesize($_FILES['Filedata']['tmp_name']);
        
    $extension str_replace("image/"""$image_mime_type['mime']);


        
    //if the image is too small we'll enlarge it
        
    if($image_mime_type[0] < "182" || $image_mime_type[1] < "270") {
           
     
    //part of the code 
    *************************$watermarkImg imagecreatefrompng($watermarkImagePath);        

    if(
    $extension == "jpeg") {
                
    $image imagecreatefromjpeg($_FILES['Filedata']['tmp_name'], **********$targetFilePath);
            } elseif (
    $extension == "png") {
                
    $image imagecreatefrompng($_FILES['Filedata']['tmp_name'], ***********$targetFilePath);
            } elseif (
    $extension == "gif") {
                
    $image imagecreatefromgif($_FILES['Filedata']['tmp_name'], ************$targetFilePath);
            } else {
                die(
    "Unsupported type");
            }

    // Set the margins for the watermark                 
    **************$marge_right 10;                 
    **************
    $marge_bottom 10;                                  

    // Get the height/width of the watermark image                
      
    *************$sx imagesx($watermarkImg);                 
    **************
    $sy imagesy($watermarkImg);                                  

    // Copy the watermark image onto our photo using the margin offsets and                  
    // the photo width to calculate the positioning of the watermark.                 
    ***********************imagecopy($image$watermarkImgimagesx($image) - $sx $marge_rightimagesy($image) - $sy $marge_bottom00imagesx($watermarkImg), imagesy($watermarkImg));                                  

    // Save image and free memory                
      
    ************imagepng($image$targetFilePath);                
      ************
    imagedestroy($image);
            
    // Target dimensions
            
    $max_width "182";
            
    $max_height "270";


            
    // Get current dimensions
            
    $old_width  imagesx($image);
            
    $old_height imagesy($image);


            
    // Calculate the scaling we need to do to fit the image inside our frame
            
    $scale max($max_width/$old_width$max_height/$old_height);


            
    // Get the new dimensions
            
    $new_width  ceil($scale*$old_width);
            
    $new_height ceil($scale*$old_height);


            
    // Create new empty image
            
    $new imagecreatetruecolor($new_width$new_height);


            
    // Resize old image into new
            
    imagecopyresampled($new$image0000$new_width$new_height$old_width$old_height);
            
    //replace temp image with the resized one


               
    imagejpeg($new$_FILES['Filedata']['tmp_name'], 99);
               
    $extension "jpg";
        } 
    // if the image is too small


        //creating the upload directory path and the filename
        
    $extension str_replace("jpeg""jpg"$extension);
        
    $upload_folder get_post_meta($escort_post_id"upload_folder"true);
        if(!
    $upload_folder) { die("No upload folder specified in custom meta field"); }
        
    $tempFile $_FILES['Filedata']['tmp_name'];
        
    $targetPath ABSPATH 'wp-content/uploads/'.$upload_folder;
        
    $targetFile =  time().rand(10009999).".".$extension;


        if ((!
    in_array($extension,$allowed_extensions))) { die("Wrong file extension"); }
        if (!
    is_dir($targetPath)) {
            if (!
    mkdir($targetPath0777true)) { die('Failed to create folder for the images!'); }
        }


        ********************* if (
    move_uploaded_file($tempFile,$targetPath."/".$targetFile.".".$targetFilePath)) {
            
    $attachment = array(
                
    'post_mime_type' => $image_mime_type['mime'],
                
    'guid' => content_url()."/uploads/".$upload_folder."/".$targetFile,
                
    'post_status' => 'inherit',
                
    'post_parent' => $escort_post_id,
                
    'post_title' => $targetFile,
                
    'post_type ' => "attachment"
            
    );

            
    // Save the attachment metadata
            
    require_once( ABSPATH 'wp-admin/includes/image.php' );
            
    $attachment_id wp_insert_attachment($attachment$targetPath."/".$targetFile$escort_post_id);
            
    $attach_data wp_generate_attachment_metadata($attachment_id$targetPath."/".$targetFile);
            
    wp_update_attachment_metadata($attachment_id$attach_data);
            echo 
    'ok';
        }
    }
    ?>

  7. #7
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    So che modificare un file php è un lavoro da retribuire... pensavo che qualcuno mi desse una mano, scusate

  8. #8
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    Risolto in altro modo. Grazie

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 © 2024 vBulletin Solutions, Inc. All rights reserved.