Visualizzazione dei risultati da 1 a 9 su 9

Discussione: parse error, perchè ?

  1. #1
    Utente bannato
    Registrato dal
    Jun 2003
    Messaggi
    1,011

    parse error, perchè ?

    Premetto che col php sono davvero una frana, stò cercando di crare uno script prendendo vari pezzi di codici già pronti, ho creato un form:

    Codice PHP:
    <?php echo "<form action=\"wp-admin/upload.php?rel_path=$rel_path&amp;action=upload\"; ?>
    Però quando vado a caricare una foto e il form lancia il file upload.php, ho questo errore:

    Parse error: syntax error, unexpected $end in upload.php on line 132

    L'errore è sull'ultima riga, la funzione è giusta perchè l'ho presa da uno script in cui funziona, io credo che non mi prenda l' action dal form, $_REQUEST non sò manco cosa sia

    Codice PHP:
    <?php

    if($_REQUEST['action'] == "upload"){
    echo 
    "<span class='highlight'>";

    //if (!get_settings('use_fileupload')){ //Checks if file upload is enabled in the config
    // echo (__("The admin disabled this function"));
    if (!current_user_can('upload_files')){
    echo(
    __('You do not have permission to upload files.'));
    }
    else {
    //$upl_path = get_settings('fileupload_realpath').$rel_path;
    $upl_path ABSPATH.'/'.get_settings('upload_path').$rel_path;
    if (!
    is_writable($upl_path)){
    //printf(__("It doesn't look like you can use the file upload feature at this time because the directory you have specified (<code>%s</code>) doesn't appear to be writable by WordPress. Check the permissions on the directory and for typos."), get_settings('fileupload_realpath').$rel_path);
    printf(__("It doesn't look like you can use the file upload feature at this time because the directory you have specified (<code>%s</code>) doesn't appear to be writable by WordPress. Check the permissions on the directory and for typos."), ABSPATH.'/'.get_settings('upload_path').$rel_path);
    }
    else {
    $allowed_types explode(' 'trim(strtolower($imagesallowed)));
    $img1_name $HTTP_POST_FILES['upl_file']['name'];
    $img1 $HTTP_POST_FILES['upl_file']['tmp_name'];

    $imgtype explode(".",$img1_name);
    $imgtype strtolower($imgtype[count($imgtype)-1]);
    //check that this is an image, no funnybusiness
    $checkthatimage getimagesize($img1);
    if (
    $checkthatimage == FALSE) {
    unlink($img1);
    die (
    __("Not a valid image file."));

    }

    //end check

    if (in_array($imgtype$allowed_types) == false) {
    echo 
    sprintf(__('File %1$s of type %2$s is not allowed.') , $img1_name$imgtype);
    }
    else {
    //file type is allowed
    if( $HTTP_POST_FILES['upl_file']['size'] > ($maxuploadsize*1024))
    echo 
    __("File is larger than allowed limit!");
    else {
    //filesize is OK
    if($HTTP_POST_FILES['upl_file']['size'] > 0){//larger than 0 is allowed:o)
    ?? $pathtofile2 $upl_path.$img1_name;
    if(
    file_exists($pathtofile2)){
    printf(__("The filename '%s' already exists!"), $img1_name);
    }
    else {
    //let's move the file
    $moved move_uploaded_file($img1$pathtofile2);
    // if move_uploaded_file() fails, try copy()
    if (!$moved) {
    $moved copy($img1$pathtofile2);
    }
    if (
    $moved) {
    printf(__("Couldn't upload your file to %s."), $pathtofile2);
    } else {
    chmod($pathtofile20666);
    @
    unlink($img1);
    }

    }

    }
    //doesn't exist
    }//>0
    }//<maxSize

    }

    }

    }
    echo 
    "</span>";
    }

    else {
    echo 
    "hallo";
    }

    ?>

  2. #2
    non hai chiuso la stringa del echo nella linea in cui dichiari il form. la versione giusta è così:

    Codice PHP:
    <?php echo '<form action="wp-admin/upload.php?rel_path=$rel_path&action=upload">'?>

  3. #3
    Utente bannato
    Registrato dal
    Jun 2003
    Messaggi
    1,011
    Originariamente inviato da OhMyGod
    non hai chiuso la stringa del echo nella linea in cui dichiari il form. la versione giusta è così:

    Codice PHP:
    <?php echo '<form action="wp-admin/upload.php?rel_path=$rel_path&action=upload">'?>
    Ma non è questo il problema, l'ho solo riportato male...l'errore è sul file upload.php, ma l'action me la dovrebbe prendere o no ?

    Non si può sapere dove lo script si blocca ? Non c'è qualche tool fatto a posta, tipo debugger ?

  4. #4
    si blocca alla linea 132; cosa c'è esattamente in questa linea?
    posta soltanto questa linea perchè nel codice che hai riportato prima non c'è la numerazione delle linee, quindi è più complicato

  5. #5
    Utente bannato
    Registrato dal
    Jun 2003
    Messaggi
    1,011
    Originariamente inviato da OhMyGod
    si blocca alla linea 132; cosa c'è esattamente in questa linea?
    posta soltanto questa linea perchè nel codice che hai riportato prima non c'è la numerazione delle linee, quindi è più complicato
    è l'ultima riga, eppure con il codice ho fatto copia e incolla, quindi è corretto

  6. #6
    Utente di HTML.it L'avatar di Graboid
    Registrato dal
    Oct 2004
    Messaggi
    619
    nel tag form serve:

    enctype="multipart/form-data"

    se vuoi fare l'upload di file.

    prova a vedere se basta questo a risolvere

  7. #7
    Utente bannato
    Registrato dal
    Jun 2003
    Messaggi
    1,011
    Originariamente inviato da Graboid
    nel tag form serve:

    enctype="multipart/form-data"

    se vuoi fare l'upload di file.

    prova a vedere se basta questo a risolvere
    C'è già, il problema è che ho postato solo una parte

  8. #8
    Utente di HTML.it L'avatar di Graboid
    Registrato dal
    Oct 2004
    Messaggi
    619
    Se l'errore te lo da' nell'ultima riga molto probabilmente e' un problema di graffe non chiuse.
    Prova così (cmq che brutto codice):

    Codice PHP:
    <?

    if($_REQUEST['action'] == "upload"){
      echo 
    "<span class='highlight'>";

      
    //if (!get_settings('use_fileupload')){ //Checks if file upload is enabled in the config
      // echo (__("The admin disabled this function"));
      
    if (!current_user_can('upload_files')){
        echo(
    __('You do not have permission to upload files.'));
      }else { 
        
    //$upl_path = get_settings('fileupload_realpath').$rel_path;
        
    $upl_path ABSPATH.'/'.get_settings('upload_path').$rel_path;
        
        
      if (!
    is_writable($upl_path)){
        
    //printf(__("It doesn't look like you can use the file upload feature at this time because the directory you have specified (<code>%s</code> ) doesn't appear to be writable by WordPress. Check the permissions on the directory and for typos."), get_settings('fileupload_realpath').$rel_path);
        
    printf(__("It doesn't look like you can use the file upload feature at this time because the directory you have specified (<code>%s</code> ) doesn't appear to be writable by WordPress. Check the permissions on the directory and for typos."), ABSPATH.'/'.get_settings('upload_path').$rel_path);
      }else {
        
    $allowed_types explode(' 'trim(strtolower($imagesallowed)));
        
    $img1_name $HTTP_POST_FILES['upl_file']['name'];
        
    $img1 $HTTP_POST_FILES['upl_file']['tmp_name'];

        
    $imgtype explode(".",$img1_name);
        
    $imgtype strtolower($imgtype[count($imgtype)-1]);
        
    //check that this is an image, no funnybusiness
        
    $checkthatimage getimagesize($img1);
        if (
    $checkthatimage == FALSE) {
          
    unlink($img1);
          die (
    __("Not a valid image file."));
        }

        
    //end check

        
    if (in_array($imgtype$allowed_types) == false) {

          echo 
    sprintf(__('File %1$s of type %2$s is not allowed.') , $img1_name$imgtype);
        }else {
    //file type is allowed
          
    if( $HTTP_POST_FILES['upl_file']['size'] > ($maxuploadsize*1024)){
            echo 
    __("File is larger than allowed limit!");
          }else {
    //filesize is OK
          
            
    if($HTTP_POST_FILES['upl_file']['size'] > 0){//larger than 0 is allowed:o)
              
    $pathtofile2 $upl_path.$img1_name;
              
              if(
    file_exists($pathtofile2)){
                
    printf(__("The filename '%s' already exists!"), $img1_name);
              }else {
                
    //let's move the file
                
    $moved move_uploaded_file($img1$pathtofile2);
                
    // if move_uploaded_file() fails, try copy()
                
    if (!$moved) {
                
    $moved copy($img1$pathtofile2);
                }
                
                if (
    $moved) {
                  
    printf(__("Couldn't upload your file to %s."), $pathtofile2);
                } else {
                  
    chmod($pathtofile20666);
                  @
    unlink($img1);
                }

              }

            }
    //doesn't exist
          
    }//>0
        
    }//<maxSize

      
    }

      }
    echo 
    "</span>";
    }else {
    echo 
    "hallo";
    }

    ?>

  9. #9
    Utente bannato
    Registrato dal
    Jun 2003
    Messaggi
    1,011
    vaccarola, c'era una graffa in +

    almeno mi sò studiato il codice

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.