Pagina 1 di 3 1 2 3 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 28
  1. #1

    Errore NaN% Barra di progressione

    Ciao a tutti

    Vorrei aggiungere una barra di progressione che indica l'avanzamento di caricamento di un file sul server utilizzando un codice che sfrutta la libreria di php apc.rfc1867

    Premetto che la pagina esistente carica correttamente il file, solo che vorrei aggiungere la barra di progressione

    La versione di PHP di xampp è la 5.3.1

    apc.rfc1867 è abilitata

    Il codice isolato funziona correttamente

    Nel file php in cui è presente il modulo dovrei aggiungere questo codice:

    codice:
    <?php 
    //get unique id
    $up_id = uniqid(); : questo l'ho tolto perchè il codice della pagina rinomina le immagini caricate con un nome univoco
    ?>
    
    <?php
    
    //process the forms and upload the files
    if ($_POST) {
    
    //specify folder for file upload: qui non riesco ad indicare la cartella corretta
    $folder = "tmp/"; 
    
    //specify redirect URL: questo l'ho tolto
    $redirect = "upload.php?success";
    
    //upload the file: qui non riesco a fare nulla
    move_uploaded_file($_FILES["file"]["tmp_name"], "$folder" . $_FILES["file"]["name"]);
    
    //do whatever else needs to be done (insert information into database, etc...)
    
    //redirect user: questo l'ho tolto essendo incluso nella pagina del modulo esistente
    header('Location: '.$redirect); die;
    }
    //
    
    ?>
    La pagina esistente riporta questo codice:

    codice:
    		// Store the uploaded files in our configured products directory
    		$uploadDirectory = ISC_BASE_PATH.'/'.GetConfig('ImageDirectory').'/configured_products_tmp/';
    		if (empty($file['existingPath'])) {
    			/**
    			 * @todo Implement temporary sharing/storage location with automatic pruning.
    			 */
    			$fileName = $fieldOptions['productfieldid'].'_'.md5(uniqid()).'.'.$extension;
    			if (!move_uploaded_file($file['tmp_name'], $uploadDirectory.$fileName)) {
    				throw new ISC_QUOTE_EXCEPTION(getLang('CanNotUploadFile'));
    			}
    		}
    		else {
    			$fileName = basename($file['existingPath']);
    		}
    Quando provo a caricare il file appare la barra di progressione con su scritto NaN% invece di un numero con % a seguito

    NaN dovrebbe significare not a number

    Non riesco ad adattare questo codice con quello già esistente, indicando la cartella e il file che al momento vengono caricati

    Grazie in anticipo

  2. #2
    Utente di HTML.it
    Registrato dal
    Oct 2009
    Messaggi
    636
    Nel codice da te postato non è visibile la parte responsabile dell'avanzamento di percentuale.

  3. #3
    Ciao longilineo

    Grazie per avermi risposto

    La pagina che contiene il form tra i tag head contiene il seguente codice:
    codice:
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.js" type="text/javascript"></script>
    <script>
    
    $(document).ready(function() { 
    //
    
    //show the progress bar only if a file field was clicked
    	var show_bar = 0;
        $('input[type="file"]').click(function(){
    		show_bar = 1;
        });
    
    //show iframe on form submit
        $("#caricafile").submit(function(){
    
    		if (show_bar === 1) { 
    			$('#upload_frame').show();
    			function set () {
    				$('#upload_frame').attr('src','upload_frame.php?up_id=ProductFields[%%GLOBAL_ProductFieldId%%]');
    			}
    			setTimeout(set);
    		}
        });
    //
    
    });
    
    </script>
    Che su clic del mouse richiama il file upload_frame.php

    Mentre il form è così:

    codice:
    <form name="caricafile" id="caricafile" method="post" action="%%GLOBAL_CartLink%%" onsubmit="return check_add_to_cart(this, %%GLOBAL_ProductOptionRequired%%)"  enctype="multipart/form-data">
    	    <input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="ProductFields[%%GLOBAL_ProductFieldId%%]"/>
    		<input type="%%GLOBAL_ProductFieldType%%" name="ProductFields[%%GLOBAL_ProductFieldId%%]" class="Textbox %%GLOBAL_FieldRequiredClass%%" size="%%GLOBAL_ProductFieldInputSize%%" value="%%GLOBAL_ProductFieldValue%%" />
        <iframe id="upload_frame" name="upload_frame" frameborder="0" border="0" src="" scrolling="no" scrollbar="no" > </iframe>
        <input name="Submit" type="submit" id="submit" value="Submit" />
    Il file upload_frame.php

    tra i tag head contiene il seguente codice:
    codice:
    <?php
    
    $url = basename($_SERVER['SCRIPT_FILENAME']);
    
    //Get file upload progress information.
    if(isset($_GET['progress_key'])) {
    	$status = apc_fetch('upload_'.$_GET['progress_key']);
    	echo $status['current']/$status['total']*100;
    	die;
    }
    //
    
    ?>
    
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.js" type="text/javascript"></script>
    <link href="style_progress.css" rel="stylesheet" type="text/css" />
    
    <script>
    $(document).ready(function() { 
    //
    
    	setInterval(function() 
    		{
    	$.get("<?php echo $url; ?>?progress_key=<?php echo $_GET['up_id']; ?>&randval="+ Math.random(), { 
    		//get request to the current URL (upload_frame.php) which calls the code at the top of the page.  It checks the file's progress based on the file id "progress_key=" and returns the value with the function below:
    	},
    		function(data)	//return information back from jQuery's get request
    			{
    				$('#progress_container').fadeIn(100);	//fade in progress bar	
    				$('#progress_bar').width(data +"%");	//set width of progress bar based on the $status value (set at the top of this page)
    				$('#progress_completed').html(parseInt(data) +"%");	//display the % completed within the progress bar
    			}
    		)},500);	//Interval is set at 500 milliseconds (the progress bar will refresh every .5 seconds)
    
    });
    
    
    </script>
    Mentre tra i tag body il seguente:
    codice:
    <body style="margin:0px">
    
    <div id="progress_container">
    	<div id="progress_bar">
      		 <div id="progress_completed"></div>
    	</div>
    </div>
    
    </body>
    Quindi upload_frame.php dovrebbe controllare lo stato di avanzamento dell'upload tramite il valore di up_id (indicato nell'head della pagina che contiene il modulo di caricamento)

    up_id prende il valore dal value= %%GLOBAL_ProductFieldId%% che a pagina caricata si traduce nell'id del prodotto, ma non dell'immagine

    codice:
    <input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="ProductFields[%%GLOBAL_ProductFieldId%%]"/>
    Pensi che l'errore stia lì?

    Partendo da:
    codice:
    define("NOME", "valore");
    codice:
    define("$folder", "$uploadDirectory");
    codice:
    define("$up_id", "$fileName");
    E' possibile fare una cosa del genere?

    Grazie ancora

  4. #4
    up

  5. #5
    Utente di HTML.it
    Registrato dal
    Oct 2009
    Messaggi
    636
    function(data) //return information back from jQuery's get request
    {
    $('#progress_container').fadeIn(100); //fade in progress bar
    $('#progress_bar').width(data +"%"); //set width of progress bar based on the $status value (set at the top of this page)
    $('#progress_completed').html(parseInt(data) +"%"); //display the % completed within the progress bar
    }
    )},500);

    Nella function fai console.log(data) e vedi cosa effettivamente ti viene tornato dalla richiesta asincrona

  6. #6
    Ciao longilineo

    Grazie di nuovo per avermi risposto

    Non ho capito come eseguire la funzione che mi hai suggerito e ho provato così:

    codice:
    function console.log(data)	//return information back from jQuery's get request
    Non ho ottenuto alcun messaggio, penso proprio di aver sbagliato

  7. #7
    Ho fatto così:
    codice:
    $(document).ready(function() { console.log(data);
    Il messaggio restituito da webdeveloper di firebug è

    Errore: data is not defined
    File sorgente: upload_frame.php?up_id=ProductFields[29080]
    Riga: 6

  8. #8
    Utente di HTML.it
    Registrato dal
    Oct 2009
    Messaggi
    636
    console.log(data) lo devi fare dove data è definito quindi:

    codice:
    function(data)	//return information back from jQuery's get request
    {
        console.log(data); //devi farlo qui!!!
        $('#progress_container').fadeIn(100);	
        $('#progress_bar').width(data +"%");
        $('#progress_completed').html(parseInt(data) +"%");
    })},500);

  9. #9
    Ho fatto come mi hai indicato, però non viene visulizzato nulla a monitor

  10. #10
    Utente di HTML.it
    Registrato dal
    Oct 2009
    Messaggi
    636
    infatti devi dare un'occhiata alla console

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.