Teilweise leeres Array bei File-Upload

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Teilweise leeres Array bei File-Upload

    Hallo zusammen.

    Ich habe folgendes Problem beim File Upload:
    Der Filename und Mine-Type wird erfasst, ab tmp_name ist aber Schicht. Das tmp Verzeichniss ist das Standard Serververzeichnis.

    Auch wenn ich die Upload_dir in der php.ini explizit in /tmp ändere
    gehts nicht. Vor kurzem gings noch.
    Ich glaub ich hab mir nen Fehler eingebaut, seh ihn aber nicht.
    Hier mal der Code dazu:
    PHP-Code:
    <?php
                 
    for ($i=0$i<=9$i=$i+1)
    {
     
      
    $fname=$_FILES['userfile'][$i];
      
    $f_origname=$_FILES['userfile']['name'][$i];
      
    $f_type=$_FILES['userfile']['type'][$i];
      
    $f_tmpname=$_FILES['userfile']['tmp_name'][$i];
      
    $f_error=$_FILES['userfile']['error'][$i];
      
    $f_size=$_FILES['userfile']['size'][$i];
     
    //if ($f_size > 0) {
      
    echo("\$f_origname=$f_origname <br>");
      echo(
    "\$f_type=$f_type <br>");
      echo(
    "\$f_tmpname=$f_tmpname <br>");
      echo(
    "\$f_error=$f_error <br>");
      echo(
    "\$f_size=$f_size <br>");

      
    $ziel="/var/www/zeit/zeit-lan/html/objektbilder/";
      
    $errmsg="";
      
    $warn="";
      
    // Kontrolle der Dateigröße
      
    $fmax25000 ;
      if(
    $f_size>$fmax) {
        
    $errmsg.="Datei zu gross <br>";
      }
      
    // Kontrolle der Dateitype
      
    $fe=array("text/plain","image/jpeg","image/gif");
      
    $feerr="Dateitype unzulässig <br>";
      foreach ((array)
    $fe as $me) {
        if(
    $f_type==$me) {$feerr="";}
      }
      if(
    strlen($feerr)) {$errmsg.=$feerr;}
      
    // Existiert die Datei ?
      
    $savename=$ziel.$f_origname;
      if(
    file_exists($savename)) {
        
    $warn.="(Datei überschrieben) <br>";
      }

      
    // Datei sichern
      
    if(strlen($errmsg)) {
        echo(
    "Upload verweigert: <br>$errmsg ");
      }
      else {
        echo(
    "Upload von $f_origname");
        
    $savename=$ziel.$f_origname;
        
    $r=copy($f_tmpname,$savename);
        if(
    $r) {
          echo(
    " war erfolgreich. <br>");
          echo(
    $warn);
        }
        else {echo(
    " fehlerhaft ! <br>");}
      }
    // }
    }
    ?>
    Sieht einer mehr als ich ?

    #micha#

  • #2
    Wo ist denn genau das Problem?

    Übrigens nimmt man heutzutage move_uploaded_file anstatt copy.
    hopka.net!

    Kommentar


    • #3
      Das Problem sieht so aus:

      PHP-Code:
      Array
      (
          [
      userfile] => Array
              (
                  [
      name] => Array
                      (
                          [
      0] => VEREIN.jpg
                          
      [1] => 
                          [
      2] => 
                          [
      3] => 
                          [
      4] => 
                          [
      5] => 
                          [
      6] => 
                          [
      7] => 
                          [
      8] => 
                          [
      9] => 
                      )

                  [
      type] => Array
                      (
                          [
      0] => image/jpeg
                          
      [1] => application/octet-stream
                          
      [2] => application/octet-stream
                          
      [3] => application/octet-stream
                          
      [4] => application/octet-stream
                          
      [5] => application/octet-stream
                          
      [6] => application/octet-stream
                          
      [7] => application/octet-stream
                          
      [8] => application/octet-stream
                          
      [9] => application/octet-stream
                      
      )

                  [
      tmp_name] => Array
                      (
                          [
      0] => none
                          
      [1] => none
                          
      [2] => none
                          
      [3] => none
                          
      [4] => none
                          
      [5] => none
                          
      [6] => none
                          
      [7] => none
                          
      [8] => none
                          
      [9] => none
                      
      )

                  [
      size] => Array
                      (
                          [
      0] => 0
                          
      [1] => 0
                          
      [2] => 0
                          
      [3] => 0
                          
      [4] => 0
                          
      [5] => 0
                          
      [6] => 0
                          
      [7] => 0
                          
      [8] => 0
                          
      [9] => 0
                      
      usw
      Was man heutzutage nimmt hängt immer noch von der verwendeten PHP version ab oder ?

      #Micha#

      Kommentar


      • #4
        Aha. Wie sieht denn das Formular aus?
        hopka.net!

        Kommentar


        • #5
          Re: Teilweise leeres Array bei File-Upload

          Original geschrieben von michab
          Ich habe folgendes Problem beim File Upload:
          Der Filename und Mine-Type wird erfasst, ab tmp_name ist aber Schicht. Das tmp Verzeichniss ist das Standard Serververzeichnis.
          Sieht so aus, wie wenn der Apache nicht ins tmp schreiben darf.
          Liefere entweder einen Link auf Dein phpinfo oder kontrolliere, ob safe_mode u/o open_basedir /pfad/zum/home gesetzt bzw. upload_tmp_dir falsch gesetzt sind.

          Kommentar


          • #6
            Das Formular sieht so aus.
            PHP-Code:
            <form enctype="multipart/form-data" method="post" action="new5.php?<?=SID?>">
                            <table width="100%" border="0">
                              <tr> 
                                <td width="30%"><strong><font size="2">Multimedia</font></strong></td>
                                <td width="30%"><strong><font size="1"><?php echo $strasse ?>&nbsp;<?php echo $nr ?></font></strong></td>
                                <td width="5%">&nbsp;</td>
                                <td width="16%"><strong><font size="1"><?php echo $ort ?></font></strong></td>
                                <td colspan="2">&nbsp;</td>
                                <td width="19%">&nbsp;</td>
                              </tr>
                              <tr> 
                                <td>&nbsp;</td>
                                <td><input type="hidden" name="MAX_FILE_SIZE" value="30000"></td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td width="11%">&nbsp;</td>
                                <td width="19%">&nbsp;</td>
                                <td>&nbsp;</td>
                              </tr>
                              <tr> 
                                <td>&nbsp;</td>
                                <td>Dateiname</td>
                                <td>&nbsp;</td>
                                <td>Art der Datei</td>
                                <td>Dauer/sec.<br>
                                  nur MPG </td>
                                <td>Titel im Expose</td>
                                <td>&nbsp;</td>
                              </tr>
                              <tr> 
                                <td>Datei 1</td>
                                <td height="26"> <input type="file" name="userfile[]"></td>
                                <td>&nbsp;</td>
                                <td><select name="oart110" id="oart110">
                                    <option value="L">Link</option>
                                    <option value="B">Bild</option>
                                    <option value="V">Video</option>
                                  </select></td>
                                <td><input name="odauer112" type="text" id="odauer112" size="5" maxlength="5"></td>
                                <td><input name="otext112" type="text" id="otext112" size="20" maxlength="20"></td>
                                <td>&nbsp;</td>
                              </tr>
                              <tr> 
                                <td>Datei 2</td>
                                <td><input type="file" name="userfile[]"></td>
                                <td>&nbsp;</td>
                                <td><select name="select" id="select">
                                    <option value="L">Link</option>
                                    <option value="B">Bild</option>
                                    <option value="V">Video</option>
                                  </select></td>
                                <td><input name="odauer1122" type="text" id="odauer1122" size="5" maxlength="5"></td>
                                <td><input name="otext1122" type="text" id="otext1122" size="20" maxlength="20"></td>
                                <td>&nbsp;</td>
                              </tr>
                              <tr> 
                                <td>Datei 3</td>
                                <td><input type="file" name="userfile[]"></td>
                                <td>&nbsp;</td>
                                <td><select name="select2" id="select2">
                                    <option value="L">Link</option>
                                    <option value="B">Bild</option>
                                    <option value="V">Video</option>
                                  </select></td>
                                <td><input name="odauer1123" type="text" id="odauer1123" size="5" maxlength="5"></td>
                                <td><input name="otext1123" type="text" id="otext1123" size="20" maxlength="20"></td>
                                <td>&nbsp;</td>
                              </tr>
                              <tr> 
                                <td>Datei 4</td>
                                <td><input type="file" name="userfile[]"></td>
                                <td>&nbsp;</td>
                                <td><select name="select3" id="select3">
                                    <option value="L">Link</option>
                                    <option value="B">Bild</option>
                                    <option value="V">Video</option>
                                  </select></td>
                                <td><input name="odauer1124" type="text" id="odauer1124" size="5" maxlength="5"></td>
                                <td><input name="otext1124" type="text" id="otext1124" size="20" maxlength="20"></td>
                                <td>&nbsp;</td>
                              </tr>
                              <tr> 
                                <td>Datei 5</td>
                                <td><input type="file" name="userfile[]"></td>
                                <td>&nbsp;</td>
                                <td><select name="select4" id="select4">
                                    <option value="L">Link</option>
                                    <option value="B">Bild</option>
                                    <option value="V">Video</option>
                                  </select></td>
                                <td><input name="odauer1125" type="text" id="odauer1125" size="5" maxlength="5"></td>
                                <td><input name="otext1125" type="text" id="otext1125" size="20" maxlength="20"></td>
                                <td>&nbsp;</td>
                              </tr>
                              <tr> 
                                <td>Datei 6</td>
                                <td><input type="file" name="userfile[]"></td>
                                <td>&nbsp;</td>
                                <td><select name="select5" id="select5">
                                    <option value="L">Link</option>
                                    <option value="B">Bild</option>
                                    <option value="V">Video</option>
                                  </select></td>
                                <td><input name="odauer1126" type="text" id="odauer1126" size="5" maxlength="5"></td>
                                <td><input name="otext1126" type="text" id="otext1126" size="20" maxlength="20"></td>
                                <td>&nbsp;</td>
                              </tr>
                              <tr> 
                                <td>Datei 7</td>
                                <td><input type="file" name="userfile[]"></td>
                                <td>&nbsp;</td>
                                <td><select name="select6" id="select6">
                                    <option value="L">Link</option>
                                    <option value="B">Bild</option>
                                    <option value="V">Video</option>
                                  </select></td>
                                <td><input name="odauer1127" type="text" id="odauer1127" size="5" maxlength="5"></td>
                                <td><input name="otext1127" type="text" id="otext1127" size="20" maxlength="20"></td>
                                <td>&nbsp;</td>
                              </tr>
                              <tr> 
                                <td>Datei 8</td>
                                <td><input type="file" name="userfile[]"></td>
                                <td>&nbsp;</td>
                                <td><select name="select7" id="select7">
                                    <option value="L">Link</option>
                                    <option value="B">Bild</option>
                                    <option value="V">Video</option>
                                  </select></td>
                                <td><input name="odauer1128" type="text" id="odauer1128" size="5" maxlength="5"></td>
                                <td><input name="otext1128" type="text" id="otext1128" size="20" maxlength="20"></td>
                                <td>&nbsp;</td>
                              </tr>
                              <tr> 
                                <td>Datei 9</td>
                                <td><input type="file" name="userfile[]"></td>
                                <td>&nbsp;</td>
                                <td><select name="select8" id="select8">
                                    <option value="L">Link</option>
                                    <option value="B">Bild</option>
                                    <option value="V">Video</option>
                                  </select></td>
                                <td><input name="odauer1129" type="text" id="odauer1129" size="5" maxlength="5"></td>
                                <td><input name="otext1129" type="text" id="otext1129" size="20" maxlength="20"></td>
                                <td>&nbsp;</td>
                              </tr>
                              <tr> 
                                <td>Datei 10</td>
                                <td><input type="file" name="userfile[]"></td>
                                <td>&nbsp;</td>
                                <td><select name="select9" id="select9">
                                    <option value="L">Link</option>
                                    <option value="B">Bild</option>
                                    <option value="V">Video</option>
                                  </select></td>
                                <td><input name="odauer11210" type="text" id="odauer11210" size="5" maxlength="5"></td>
                                <td><input name="otext11210" type="text" id="otext11210" size="20" maxlength="20"></td>
                                <td>&nbsp;</td>
                              </tr>
                              <tr> 
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td><input type="submit" name="senden" value="speichern & weiter"></td>
                                <td>&nbsp;</td>
                              </tr>
                            </table>
                          </form>
            Merkwürdig ist, das das ganze schonmal funktioniert hat.
            Ich werd mir auch mal die http.conf ansehen.
            Der Apache darf in tmp schreiben, da werden die Session-ID's
            ohne Probleme abgelegt. Das dürfte also nicht die Ursache sein.
            Safe_mode ist off
            upload_tmp_dir ist in der php.ini leer, das heist standard.
            Hab jetzt nochmal in meiner vhost.conf php_admin_value upload_tmp_dir gesetzt. Keine Änderung

            Zugriffsrechte sind ok.
            Php.ini kann ich nicht verlinken, ist ein localer Server.

            Kommentar


            • #7
              Original geschrieben von michab
              [B]Das Formular sieht so aus.
              PHP-Code:
              <form enctype="multipart/form-data" method="post" action="new5.php?<?=SID?>">
              <input type="hidden" name="MAX_FILE_SIZE" value="30000">

              <input type="file" name="userfile[]"> ###
              <input type="file" name="userfile[]"> ###
              </form>
              Die file Tags würde ich noch mal kontrollieren:
              11.12. Wie kann ich mehrere Dateien auf einmal uploaden?
              http://www.dclp-faq.de/q/q-formular-...ch-upload.html

              Merkwürdig ist, das das ganze schonmal funktioniert hat.
              Ich werd mir auch mal die http.conf ansehen.
              Hier mal als Beispiel ein Template, wie ich normale Virtualhosts anlege:
              Code:
              <VirtualHost {IP}:80>
                  ServerName {DOMAIN}
                  ServerAlias [url]www.[/url]{DOMAIN}
                  DocumentRoot /home/www/{USER}/##DOMAIN##/html
                  CustomLog /home/www/{USER}/{DOMAIN}/log/access_log common
                  CustomLog /home/www/{USER}/{DOMAIN}/log/referer_log referer
                  CustomLog /home/www/{USER}/{DOMAIN}/log/agent_log agent
                  CustomLog /home/www/{USER}/{DOMAIN}/log/access_log combined
                  AddType application/x-httpd-php .php
                  php_admin_flag register_globals Off
                  php_admin_flag safe_mode On
                  php_admin_value include_path .
                  php_admin_value open_basedir /home/www/{USER}/{DOMAIN}/
                  php_admin_value upload_tmp_dir /home/www/{USER}/{DOMAIN}/tmp
                  php_admin_value session.save_path /home/www/{USER}/{DOMAIN}/tmp
              </VirtualHost>
              Die Platzhalter {DOMAIN} usw. sind selbsterklärend.

              Kommentar


              • #8
                Tja, die virtual host konfiguration ist bei mir ähnlich.
                Debian legts ein bischen anders an, aber das ist marginal.

                Das mit der TAG überprüfung hab ich jetzt nicht verstanden.
                Das scheint mir in meinem Script logisch zu sein.

                #micha#

                Kommentar


                • #9
                  Ich glaub's nicht, es liegt an der Dateiendung.
                  Gif Dateien gehen ohne Probleme.

                  Ich werd dem Schweinchen schon schlachten auch wenn es quickt

                  #micha#

                  Kommentar


                  • #10
                    Lösung:

                    Ich habe die Zeile :
                    PHP-Code:
                     $fe=array("text/plain","image/jpeg","image/gif"); 
                    gegen
                    PHP-Code:
                     $fe=array("text/plain","image/gif","image/jpeg"); 
                    getauscht.

                    Jetzt geht es problemlos. Weis der Teufel warum.

                    #micha#

                    Kommentar


                    • #11
                      Original geschrieben von michab
                      Weis der Teufel warum.
                      Ich auch nicht. Dein Script war mir nämlich viel zu wüst, um den verschlungenen Pfaden Deines Algorithmusses zu folgen.

                      zB.: sowas ist mir zu hoch:
                      PHP-Code:
                        $fe=array("text/plain","image/jpeg","image/gif");
                        
                      $feerr="Dateitype unzulässig <br>";
                        foreach ((array)
                      $fe as $me) {
                          if(
                      $f_type==$me) {$feerr="";}
                        } 
                      1. würde ich die Arraydefinition außerhalb der FOR Schleife anordnen.
                      2. würde ich die Fehlermeldung als Konstante definieren
                      3. würde ich die Zulässigkeit des Contenttyps anders prüfen:
                      PHP-Code:
                      $ok in_array($f_type$fe);
                      # ...
                      if (!$ok) print $feerr
                      4. würde ich sowas nicht tun:
                      PHP-Code:
                      for ($i=0$i<=9$i=$i+1){ 
                      sondern das:
                      PHP-Code:
                      $n count($_FILES['userfile']['name']);
                      for (
                      $i=0$i $n$i++) { 
                      usw.
                      Zuletzt geändert von meikel; 21.05.2004, 01:17.

                      Kommentar

                      Lädt...
                      X