[PHP] Dateiupload funktioniert nur teilweise

Dieses Thema im Forum "Webentwicklung" wurde erstellt von SeXy, 25. März 2007 .

  1. 25. März 2007
    Dateiupload funktioniert nur teilweise

    Moin!
    Habe auf meinem Webspace eine selbstgebastelte gallerie installiert.

    Mit folgendem Code:
    PHP:
    <? php
        
    if( $_SESSION [ 'status' ] >  "1" ) {
            if(isset(
    $_POST [ 'submit' ])) {
                
    $sql  'SELECT * FROM gallerie_subcats WHERE ID = "' . checkid ( $_GET [ 'subcat' ]). '"' ;
                
    $res  mysql_query ( $sql ) OR die( mysql_error ());
                
    $row  mysql_fetch_assoc ( $res );
                
                
    // Bild speichern
                
                
    $dir  'images/gallerie/pics/' . $row [ 'cat' ]. '/' . $row [ 'ID' ]. '/' ;
                
                
    $zeichen  = array( date  ( 'd' ),  date  ( 'm' ),  date  ( 'Y' ),  date  ( 'H' ),  date  ( 'i' ),  date  ( 's' ));
                
    $indizes  array_rand ( $zeichen , 3 );
                
    $name  $zeichen [ $indizes [ 0 ]]. $zeichen [ $indizes [ 1 ]]. $zeichen [ $indizes [ 2 ]];
                
    $file  $name . $_FILES [ 'picture' ][ 'name' ];
                echo 
    $file ;
                if(!
    file_exists ( $dir )) {
                    @
    mkdir ( $dir );
                    
    move_uploaded_file ( $_FILES [ 'picture' ][ 'tmp_name' ],  $dir . $file );
                } else {
                    
    move_uploaded_file ( $_FILES [ 'picture' ][ 'tmp_name' ],  $dir . $file );
                }
                
                
    // Thumbnail erstellen
                
    $size  getimagesize ( " $dir$file " );                   # Liest Größeninformationen der Grafik in ein Array
                
    $width  $size [ 0 ];                                   # Speichert die Breite in $width
                
    $height  $size [ 1 ];                                  # Speichert die Höhe in $height
                
                
    $width_tn  TN_WIDTH ;                                # Legt die Breite des zu erstellenden Thumbnails fest (In config.php zu verstellen)
                
    $height_tn  intval ( $height  $width_tn  $width );   # Legt automatisch die Höhe des Thubnails fest
                
                // Thumbnail speichern
                
    $tn_dir  'images/gallerie/thumbs/' . $row [ 'cat' ]. '/' . $row [ 'ID' ]. '/' ;
                
    $picture  ImageCreateFromJPEG ( " $dir$file " );
                
    $picture_tn  ImageCreateTrueColor ( $width_tn , $height_tn );
                
    ImageCopyResampled ( $picture_tn , $picture , 0 , 0 , 0 , 0 , $width_tn , $height_tn , $width , $height );
                if(!
    file_exists ( $tn_dir )) {
                    @
    mkdir ( $tn_dir );
                    @
    chmod ( $tndir 777 );
                    
    ImageJPEG ( $picture_tn , " $tn_dir$file " , 95 );
                } else {
                    @
    chmod ( $tndir 777 );
                    
    ImageJPEG ( $picture_tn , " $tn_dir$file " , 95 );
                }
             
            } else {
    ?>
    <form enctype="multipart/form-data" action="" method="post">
    Bild:<br>
    <input type="file" name="picture"></input><br>
    <br>
    <input type="submit" value="Uploaden" name="submit"></input>
    </form>
    <?php
            
    }
        }
    ?>

    Funktioniert der Dateiupload einwandfrei.

    Mit folgendem bekomme ich leider einen socket error:
    PHP:
    <? php


    global  $_ju_listener $_ju_uploadRoot $_ju_fileDir $_ju_thumbDir $_ju_maxSize ;

    // Include a file which provides several helper functions and is configured through the jupload.cfg.php
    require( '../../../inc/config.php' );
    include_once(
    dirname ( __FILE__ ) .  "/inc/jupload.inc.php" );
    $zeichen  = array( date  ( 'd' ),  date  ( 'm' ),  date  ( 'Y' ),  date  ( 'H' ),  date  ( 'i' ),  date  ( 's' ));
    $indizes  array_rand ( $zeichen , 3 );
    $name  $zeichen [ $indizes [ 0 ]]. $zeichen [ $indizes [ 1 ]]. $zeichen [ $indizes [ 2 ]];

    // Upload is starting
    $_ju_listener -> onStart ( $_SERVER [ "HTTP_X_JUPLOAD_ID" ]);


    foreach( $_FILES  as  $tagname => $fileinfo ) {
        
    // get the name of the temporarily saved file (e.g. /tmp/php34634.tmp)
        
    $tempPath  $fileinfo [ 'tmp_name' ];

        
    // The filename and relative path within the Upload-Tree (eg. "/my documents/important/Laura.jpg")
        
    $relativePath  $_POST [ $tagname  '_relativePath' ];
        
    $relativePath  $name . substr ( $relativePath 1 );
        
        
    // Do we have a valid file?
        
    if (! checkSavePath ( $relativePath ) || ! $_ju_listener -> checkValid ( $relativePath $tempPath )) {
            continue;
        }
        
        
    $files [ $relativePath ] =  $tempPath ;
    }

    if (
    $files ) {
        foreach (
    $files  as  $relativePath  =>  $tempPath )  {
            
    // Do we have a thumbnail? If it is not a thumbnail, it is a regular file.
            
    $isThumb  $_POST [ $tagname  '_thumbnail' ];
        
            
    // Where to save the file? Determine the target-directory, depending on if it is a thumbnail or a file
            
    $filepath  $_ju_uploadRoot  . ( $isThumb  $_ju_thumbDir  $_ju_fileDir ) .  '/' . $relativePath ;
        
            
    // Create folders
            
    mkdirs ( dirname ( $filepath  normalize ( $filepath )));
            
            
    // Move the temporary file to the target directory
            
    move_uploaded_file ( $tempPath $filepath ) or die( "Error while moving temporary file to target path: "  $relativePath );
            
    $sql  'INSERT INTO gallerie_pictures
                                (name,
                                 time,
                                 uploader,
                                 cat,
                                 subcat)
                            VALUES
                                ("'
    . $relativePath . '",
                                 "'
    . time (). '",
                                 "'
    . $row [ 'uploader' ]. '",
                                 "'
    . $row [ 'cat' ]. '",
                                 "'
    . $row [ 'subcat' ]. '")' ;
                    
    mysql_query ( $sql ) OR die( mysql_error ());
    ?>
    <?php
    // Thumbnail erstellen
    //////////////////////

    // Anmerkungen:
    //
    // $dir = Pfad für das Verzeichnis, in dem sich das upgeloadete Bild befindet
    // $filename = dateiname.jpg

    // Größe des Bildes auslesen

    $size  getimagesize ( " $filepath " );
    $width  $size [ 0 ];
    $height  $size [ 1 ];

    // Breite des Thumbnails festlegen (Höhe wird automatisch angepasst)

    $width_tn  TN_WIDTH ;
    $height_tn  intval ( $height  $width_tn  $width );
    if(
    $height_tn  TN_HEIGHT ) {
        
    $height_tn  TN_HEIGHT ;
    }

    // Bei GD < 2.0.1: ImageCreateTrueColor -> ImageCreate, ImageCopyResampled -> ImageCopyResized


    if( $size [ 2 ]== 1 ) { 
      
    // GIF 
      
    $picture  ImageCreateFromGIF ( " $filepath " ); 
      
    $picture_tn  ImageCreateTrueColor ( $width_tn , $height_tn ); 
      
    ImageCopyResampled ( $picture_tn , $picture , 0 , 0 , 0 , 0 , $width_tn , $height_tn , $width , $height ); 
      
    ImageGIF ( $picture_tn , " $_ju_uploadRoot$_ju_thumbDir / $relativePath " , 95 ); 
      } 

      if(
    $size [ 2 ]== 2 ) { 
      
    // JPG 
      
    $picture  ImageCreateFromJPEG ( " $filepath " ); 
      
    $picture_tn  ImageCreateTrueColor ( $width_tn , $height_tn ); 
      
    ImageCopyResampled ( $picture_tn , $picture , 0 , 0 , 0 , 0 , $width_tn , $height_tn , $width , $height ); 
      
    ImageJPEG ( $picture_tn , " $_ju_uploadRoot$_ju_thumbDir / $relativePath " , 95 ); 
      } 

      if(
    $size [ 2 ]== 3 ) { 
      
    // PNG 
      
    $picture  ImageCreateFromPNG ( " $filepath " ); 
      
    $picture_tn  ImageCreateTrueColor ( $width_tn , $height_tn ); 
      
    ImageCopyResized ( $picture_tn , $picture , 0 , 0 , 0 , 0 , $width_tn , $height_tn , $width , $height ); 
      
    ImagePNG ( $picture_tn , " $_ju_uploadRoot$_ju_thumbDir / $relativePath " , 95 ); 
      }

    ?>
    <?php
                    
    // Tell the listener that another file has successfully been received.
            
    $_ju_listener -> onReceived ( $filepath $relativePath $isThumbs );
        }
    }

    $_ju_listener -> finished ();
    echo 
    '<meta http-equiv="refresh" content="1; URL=index.php?site=gallerie_subcat&ID=' . $row [ 'ID' ]. '">' ;
    ?>
    Vielleicht hilft die Ordnerstruktur:
    Mainverzeichnis: party/
    Darin befinden sich folgende Verzeichnisse:
    party/jupload/scripts/php/jupload-post.php <- die Datei, mit der der upload nicht funzt
    party/images/gallerie/thumbs/ID/ID
    party/images/gallerie/pics/ID/ID
    party/files/gallerie_picture_addsingle.php <- die datei, mit der der Upload funktioniert.

    Ich kann mir nicht erklären, wieso es mit der einen nicht funktioniert. Auf localhost und eine funpic server ist das ganze komplett unverändert (bis auf die config eben) installiert und läuft einwandfrei.
    Die jupload-post.php wird von einem JavaApplet (http://www.jupload.biz) aufgerufen. Evtl. kann das den Fehler verursachen. Aber warum sollte es dann auf dem funpic server laufen?

    Bin komplett ratlos und bitte um Hilfe.
     
  2. 26. März 2007
    AW: Dateiupload funktioniert nur teilweise

    mach mal vor der zeile:
    move_uploaded_file($tempPath, $filepath)
    folgenden befehl: die("Filepath: ".$filepath);
    und sag dann mal was da ausgegeben wird
    da müsste dann ja ../../../../images/gallerie/pics/ID/ID stehen (wenn ich richtig gezählt habe)
     
  3. 26. März 2007
    AW: Dateiupload funktioniert nur teilweise

    Hab jetzt mal testweise ein normales Formular erstellt:
    PHP:
    < form enctype = "multipart/form-data"  action = "jupload-post.php"  method = "post" >
    Bild :< br >

    <
    input type = "hidden"  name = "tmp"  value = "77" ></ input >
    <
    input type = "hidden"  name = "relativePath"  value = "/5.jpg" ></ input >
    <
    input type = "hidden"  name = "virtual"  value = "0" ></ input >
    <
    input type = "hidden"  name = "thumbnail"  value = "0" ></ input >
    <
    input type = "hidden"  name = "image"  value = "1" ></ input >
    <
    input type = "hidden"  name = "lastModified"  value = "1173382311265" ></ input >
    <
    br >
    <
    input type = "file"  name = "picture" ></ input >< br >
    <
    br >
    <
    input type = "submit"  value = "Uploaden"  name = "submit" ></ input >
    </
    form >             
    Um eben zu sehen, was dabei herauskommt. errors usw. zeigt er mir mit dem Applet nämnlich irgendwie nicht an
    Habe jetzt folgendes bekommen:
    Code:
    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /srv/www/vhosts/eutin.basepage.de/httpdocs/party/jupload_biz/scripts/php/jupload-post.php:2) in /srv/www/vhosts/eutin.basepage.de/httpdocs/party/inc/config.php on line 3
    
    Notice: Undefined index: HTTP_X_JUPLOAD_ID in /srv/www/vhosts/eutin.basepage.de/httpdocs/party/jupload_biz/scripts/php/jupload-post.php on line 26
    
    Warning: Cannot modify header information - headers already sent by (output started at /srv/www/vhosts/eutin.basepage.de/httpdocs/party/jupload_biz/scripts/php/jupload-post.php:2) in /srv/www/vhosts/eutin.basepage.de/httpdocs/party/jupload_biz/scripts/php/listener/JUDefaultListener.class.php on line 25
    Invalid request.
    
    Was mir auch nicht sehr viel weiterhilft. Was hat das mit dem HTTP_X_JUPLOAD_ID auf sich?
    Bin total am Verzweifeln hier.
    Aber es kann doch auch nicht am code liegen, wenn es auf nem anderen Server läuft.
     
  4. Video Script

    Videos zum Themenbereich

    * gefundene Videos auf YouTube, anhand der Überschrift.