Formulare: Value für File-Feld

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

  • Formulare: Value für File-Feld

    Hallo,

    Aus Sicherheitsgründen gibt es bei aktuellen Browsern keine Vorbelegung für File-Felder in Formularen.

    Gibt es irgendeinen Work-Arround oder bekomme ich noch irgendwo einen Browser, der zwar JavaScript schon unterstützt, aber noch Vorbelegungen für File-Felder zulässt?

    Was ich vorhabe: Per php einen lolakeln Ordner auslesen, ein Formular erstellen und per Javascript abschicken. So möchte ich den manuellen Upload bei www.free-webspace.biz etwas bequemer machen. (FTP ist bei diesem Provider nicht möglich).

    PHP-Code:
        echo '<input type="file" value="'.$dateien[$i].'" name="file'.$i.'"><br />'
    Gruß,
    syco23
    Zuletzt geändert von syco23; 30.10.2005, 18:53.
    [COLOR=darkblue].: 1+1=23 :.[/COLOR]

  • #2
    Wenn du sowieso PHP zur Verfügung hast, verstehe ich nicht, wieso du dann noch einen Browser "automatisieren" musst??

    Bau ne Socketverbindung zum HTTP-Server des Hosters auf, und sende die entsprechenden Files rüber...

    Kommentar


    • #3
      Bau ne Socketverbindung zum HTTP-Server des Hosters auf, und sende die entsprechenden Files rüber...
      .. hm, ja wenn du mir sagst wie das geht..
      [COLOR=darkblue].: 1+1=23 :.[/COLOR]

      Kommentar


      • #4
        Original geschrieben von syco23
        .. hm, ja wenn du mir sagst wie das geht..
        (cooler Smilie )
        http://de2.php.net/sockets

        Kommentar


        • #5
          Fatal error: Call to undefined function: socket_create() in..
          -> bekomme ich sowohl am domainfactory-Webspace als auch lokal mit XAMPP.
          [COLOR=darkblue].: 1+1=23 :.[/COLOR]

          Kommentar


          • #6
            Original geschrieben von syco23
            -> bekomme ich sowohl am domainfactory-Webspace als auch lokal mit XAMPP.
            Wo hast'n diese Funktion gefunden???
            Zur Erstellung eines Sockets dient die Funktion "fsockopen"...

            Kommentar


            • #7
              eigentlich sollte man bei deiner signatur, dir den link hier mit 'ner keule um die ohren hauen: http://www.php-faq.de/q/q-code-upload.html
              Kissolino.com

              Kommentar


              • #8
                Wo hast'n diese Funktion gefunden???
                http://at.php.net/sockets
                http://www.php-faq.de/q/q-code-upload.html
                Das ist jetzt peinlich. Ich kannte den Code, nur habe ich ihn gar nicht benutzt, weil ich dachte Socket-Funktionen würde generell nicht gehen, tun sie aber doch

                Nun stehe ich wieder an. Ich möchte eine Datei "datei.html" hochladen. Wie muss ich den Code anpassen?
                PHP-Code:

                <?php

                // Andreas Bohne-Lang / [email]a.bohne@dkfz.de[/email] / 22.10.2001 / GPL
                // Ergaenzt: 19.9.2003

                function PostToHost($host$port$path$referer$data_to_send)
                {
                     
                $dc 0;
                     
                $bo="-----------------------------305242850528394";

                     
                $fp fsockopen($host$port$errno$errstr);
                     if (!
                $fp) {
                         echo 
                "errno: $errno \n";
                         echo 
                "errstr: $errstr\n";
                         return 
                $result;
                     }

                     
                fputs($fp"POST $path HTTP/1.0\n");
                     
                fputs($fp"Host: $host\n");
                     
                fputs($fp"Referer: $referer\n");
                     
                fputs($fp"User-Agent: Mozilla/4.05C-SGI [en] (X11; I; IRIX 6.5 IP22)\n");
                     
                fputs($fp"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*\n");
                     
                fputs($fp"Accept-Charset: iso-8859-1,*,utf-8\n");
                     
                fputs($fp"Content-type: multipart/form-data; boundary=$bo\n");

                     foreach(
                $data_to_send as $key=>$val) {
                         
                $ds =sprintf("--%s\nContent-Disposition: form-data; name=\"%s\"\n\n%s\n"$bo$key$val);
                         
                $dc += strlen($ds);
                     }
                     
                $dc += strlen($bo)+3;
                     
                fputs($fp"Content-length: $dc \n");
                     
                fputs($fp"\n");

                     foreach(
                $data_to_send as $key=>$val) {
                         
                $ds =sprintf("--%s\nContent-Disposition: form-data; name=\"%s\"\n\n%s\n"$bo$key$val);
                         
                fputs($fp$ds );
                     }
                     
                $ds "--".$bo."--\n";
                     
                fputs($fp$ds);

                     while(!
                feof($fp)) {
                         
                $res .= fread($fp1);
                     }
                     
                fclose($fp);

                     return 
                $res;
                }

                // Fuer eine ASCII-Datei kann man es so machen
                // bei bin-Daten ueber fread gehen

                $fa file("datei.html");

                // Konkretes Beispiel - Eine Chemie-Datei
                $xf="Content-Type: chemical/x-pdb\n\n"implode(""$fa);

                $data["disk"]            = "on";
                $data["file\"; filename=\"datei.html"]        = $xf;
                $data["smiles"]          = "";
                $data["hadd"]            = "add";
                $data["aroresolver"]     = "on";
                $data["format"]          = "gif";
                $data["interlace"]       = "1";
                $data["width"]           = "600";
                $data["height"]          = "400";
                $data["atomcolor"]       = "Black";
                $data["asymbol"]         = "xsymbol";
                $data["hcolor"]          = "";
                $data["csymbol"]         = "special";
                $data["hsymbol"]         = "special";
                $data["bondcolor"]       = "Black";
                $data["bgcolor"]         = "White";
                $data["border"]          = "12";
                $data["bonds"]           = "8";
                $data["wedges"]          = "1";
                $data["dashes"]          = "1";
                $data["crop"]            = "2";
                $data["align"]           = "none";
                $data["coord"]           = "0";
                $data["imagemap"]        = "none";
                $data["headercolor"]     = "Black";
                $data["header"]          = "";
                $data["footercolor"]     = "Black";
                $data["footer"]          = "";
                $data["commenttype"]     = "none";
                $data["comment"]         = "";
                $data["structure"]       = "none";

                $x PostToHost (
                       
                "www.free-webspace.biz",
                       
                80,
                       
                "/dateimanager.php",
                       
                "http://www.free-webspace.biz/dateimanager.php",
                       
                $data
                      
                );

                /*
                // Diesen Teil kann man bestimmt noch optimieren ;-)
                $fp = fopen("struktur.gif", "wb");
                $tok = 0;
                for ($i=20; $i<strlen($x); $i++){
                    if ((substr($x,$i,1)=="\n") || (substr($x,$i,1)=="\r")) {
                        $tok++;
                        if($tok>=3) break;
                    } else {
                        $tok=0;
                    }
                }
                $i++; $i++;
                printf(" %d %d %d \n", $i, strlen($x), strlen($x)-$i);
                fwrite($fp, substr($x,$i,strlen($x)-$i));
                fclose($fp);

                $fp = fopen("struktur.xxx", "wb");
                fwrite($fp, $x, strlen($x));
                fclose($fp);
                */
                ?>
                Außerdem: free-webspace.biz verwendet vermutlich Cookies. Muss ich für die Authentifizierung noch einen Code einbauen oder reicht es wenn ich das Script in einem Fenster ausfürhe in dem ich mich dafür bei free-webspace.biz eingeloggt habe?
                [COLOR=darkblue].: 1+1=23 :.[/COLOR]

                Kommentar


                • #9
                  Schau dir doch mal die Snoopy-Class an, welche afaik genau dein Problem mit dem POST der Dateien lösen könnte. Eine entsprechende Schleife und dein Problem sollte gelöst sein. In wiefern auch Cookies "vorgetäuscht" werden weiß ich imo nicht.

                  Kommentar


                  • #10
                    Ich sehe bei Snoopy keine Möglichkeit, Dateien hochzuladen:

                    Readme:
                    NAME:

                    Snoopy - the PHP net client v1.2

                    SYNOPSIS:

                    include "Snoopy.class.php";
                    $snoopy = new Snoopy;

                    $snoopy->fetchtext("http://www.php.net/");
                    print $snoopy->results;

                    $snoopy->fetchlinks("http://www.phpbuilder.com/");
                    print $snoopy->results;

                    $submit_url = "http://lnk.ispi.net/texis/scripts/msearch/netsearch.html";

                    $submit_vars["q"] = "amiga";
                    $submit_vars["submit"] = "Search!";
                    $submit_vars["searchhost"] = "Altavista";

                    $snoopy->submit($submit_url,$submit_vars);
                    print $snoopy->results;

                    $snoopy->maxframes=5;
                    $snoopy->fetch("http://www.ispi.net/");
                    echo "<PRE>\n";
                    echo htmlentities($snoopy->results[0]);
                    echo htmlentities($snoopy->results[1]);
                    echo htmlentities($snoopy->results[2]);
                    echo "</PRE>\n";

                    $snoopy->fetchform("http://www.altavista.com");
                    print $snoopy->results;

                    DESCRIPTION:

                    What is Snoopy?

                    Snoopy is a PHP class that simulates a web browser. It automates the
                    task of retrieving web page content and posting forms, for example.

                    Some of Snoopy's features:

                    * easily fetch the contents of a web page
                    * easily fetch the text from a web page (strip html tags)
                    * easily fetch the the links from a web page
                    * supports proxy hosts
                    * supports basic user/pass authentication
                    * supports setting user_agent, referer, cookies and header content
                    * supports browser redirects, and controlled depth of redirects
                    * expands fetched links to fully qualified URLs (default)
                    * easily submit form data and retrieve the results
                    * supports following html frames (added v0.92)
                    * supports passing cookies on redirects (added v0.92)


                    REQUIREMENTS:

                    Snoopy requires PHP with PCRE (Perl Compatible Regular Expressions),
                    which should be PHP 3.0.9 and up. For read timeout support, it requires
                    PHP 4 Beta 4 or later. Snoopy was developed and tested with PHP 3.0.12.

                    CLASS METHODS:

                    fetch($URI)
                    -----------

                    This is the method used for fetching the contents of a web page.
                    $URI is the fully qualified URL of the page to fetch.
                    The results of the fetch are stored in $this->results.
                    If you are fetching frames, then $this->results
                    contains each frame fetched in an array.

                    fetchtext($URI)
                    ---------------

                    This behaves exactly like fetch() except that it only returns
                    the text from the page, stripping out html tags and other
                    irrelevant data.

                    fetchform($URI)
                    ---------------

                    This behaves exactly like fetch() except that it only returns
                    the form elements from the page, stripping out html tags and other
                    irrelevant data.

                    fetchlinks($URI)
                    ----------------

                    This behaves exactly like fetch() except that it only returns
                    the links from the page. By default, relative links are
                    converted to their fully qualified URL form.

                    submit($URI,$formvars)
                    ----------------------

                    This submits a form to the specified $URI. $formvars is an
                    array of the form variables to pass.


                    submittext($URI,$formvars)
                    --------------------------

                    This behaves exactly like submit() except that it only returns
                    the text from the page, stripping out html tags and other
                    irrelevant data.

                    submitlinks($URI)
                    ----------------

                    This behaves exactly like submit() except that it only returns
                    the links from the page. By default, relative links are
                    converted to their fully qualified URL form.


                    CLASS VARIABLES: (default value in parenthesis)

                    $host the host to connect to
                    $port the port to connect to
                    $proxy_host the proxy host to use, if any
                    $proxy_port the proxy port to use, if any
                    $agent the user agent to masqerade as (Snoopy v0.1)
                    $referer referer information to pass, if any
                    $cookies cookies to pass if any
                    $rawheaders other header info to pass, if any
                    $maxredirs maximum redirects to allow. 0=none allowed. (5)
                    $offsiteok whether or not to allow redirects off-site. (true)
                    $expandlinks whether or not to expand links to fully qualified URLs (true)
                    $user authentication username, if any
                    $pass authentication password, if any
                    $accept http accept types (image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*)
                    $error where errors are sent, if any
                    $response_code responde code returned from server
                    $headers headers returned from server
                    $maxlength max return data length
                    $read_timeout timeout on read operations (requires PHP 4 Beta 4+)
                    set to 0 to disallow timeouts
                    $timed_out true if a read operation timed out (requires PHP 4 Beta 4+)
                    $maxframes number of frames we will follow
                    $status http status of fetch
                    $temp_dir temp directory that the webserver can write to. (/tmp)
                    $curl_path system path to cURL binary, set to false if none


                    EXAMPLES:

                    Example: fetch a web page and display the return headers and
                    the contents of the page (html-escaped):

                    include "Snoopy.class.php";
                    $snoopy = new Snoopy;

                    $snoopy->user = "joe";
                    $snoopy->pass = "bloe";

                    if($snoopy->fetch("http://www.slashdot.org/"))
                    {
                    echo "response code: ".$snoopy->response_code."<br>\n";
                    while(list($key,$val) = each($snoopy->headers))
                    echo $key.": ".$val."<br>\n";
                    echo "<p>\n";

                    echo "<PRE>".htmlspecialchars($snoopy->results)."</PRE>\n";
                    }
                    else
                    echo "error fetching document: ".$snoopy->error."\n";



                    Example: submit a form and print out the result headers
                    and html-escaped page:

                    include "Snoopy.class.php";
                    $snoopy = new Snoopy;

                    $submit_url = "http://lnk.ispi.net/texis/scripts/msearch/netsearch.html";

                    $submit_vars["q"] = "amiga";
                    $submit_vars["submit"] = "Search!";
                    $submit_vars["searchhost"] = "Altavista";


                    if($snoopy->submit($submit_url,$submit_vars))
                    {
                    while(list($key,$val) = each($snoopy->headers))
                    echo $key.": ".$val."<br>\n";
                    echo "<p>\n";

                    echo "<PRE>".htmlspecialchars($snoopy->results)."</PRE>\n";
                    }
                    else
                    echo "error fetching document: ".$snoopy->error."\n";



                    Example: showing functionality of all the variables:


                    include "Snoopy.class.php";
                    $snoopy = new Snoopy;

                    $snoopy->proxy_host = "my.proxy.host";
                    $snoopy->proxy_port = "8080";

                    $snoopy->agent = "(compatible; MSIE 4.01; MSN 2.5; AOL 4.0; Windows 98)";
                    $snoopy->referer = "http://www.microsnot.com/";

                    $snoopy->cookies["SessionID"] = 238472834723489l;
                    $snoopy->cookies["favoriteColor"] = "RED";

                    $snoopy->rawheaders["Pragma"] = "no-cache";

                    $snoopy->maxredirs = 2;
                    $snoopy->offsiteok = false;
                    $snoopy->expandlinks = false;

                    $snoopy->user = "joe";
                    $snoopy->pass = "bloe";

                    if($snoopy->fetchtext("http://www.phpbuilder.com"))
                    {
                    while(list($key,$val) = each($snoopy->headers))
                    echo $key.": ".$val."<br>\n";
                    echo "<p>\n";

                    echo "<PRE>".htmlspecialchars($snoopy->results)."</PRE>\n";
                    }
                    else
                    echo "error fetching document: ".$snoopy->error."\n";


                    Example: fetched framed content and display the results

                    include "Snoopy.class.php";
                    $snoopy = new Snoopy;

                    $snoopy->maxframes = 5;

                    if($snoopy->fetch("http://www.ispi.net/"))
                    {
                    echo "<PRE>".htmlspecialchars($snoopy->results[0])."</PRE>\n";
                    echo "<PRE>".htmlspecialchars($snoopy->results[1])."</PRE>\n";
                    echo "<PRE>".htmlspecialchars($snoopy->results[2])."</PRE>\n";
                    }
                    else
                    echo "error fetching document: ".$snoopy->error."\n";


                    COPYRIGHT:
                    Copyright(c) 1999,2000 ispi. All rights reserved.
                    This software is released under the GNU General Public License.
                    Please read the disclaimer at the top of the Snoopy.class.php file.


                    THANKS:
                    Special Thanks to:
                    Peter Sorger <sorgo@cool.sk> help fixing a redirect bug
                    Andrei Zmievski <andrei@ispi.net> implementing time out functionality
                    Patric Sandelin <patric@kajen.com> help with fetchform debugging
                    Carmelo <carmelo@meltingsoft.com> misc bug fixes with frames
                    [COLOR=darkblue].: 1+1=23 :.[/COLOR]

                    Kommentar


                    • #11
                      Original geschrieben von syco23
                      Ich sehe bei Snoopy keine Möglichkeit, Dateien hochzuladen:

                      Readme:
                      Zitat:
                      * easily submit form data and retrieve the results

                      in Verbindung mit dem multipart/form-data im Quelltext der snoopy-class zeigen, dass es eben doch möglich ist, Dateien hochzuladen! Das Anpassen an deine Ansprüche liegt nun an DIR...

                      Kommentar


                      • #12
                        Danke !

                        Das mit den Cookies habe ich jetzt hinbekommen, nur der Dateiupload funktioniert noch nicht:

                        PHP-Code:
                            <?
                            
                            include "Snoopy.class.php";
                            $snoopy = new Snoopy;
                            

                            $snoopy->cookies["PHPSESSID"] = "4db9c0179ecf03a4ff0017b979154889";

                            
                            $submit_url = "http://www.free-webspace.biz/dateimanager.php";
                            
                            $submit_vars = array();
                            
                            $submit_files["file1"] = "C:\\xampp\\htdocs\\docs\\upload-free-webspace\\datei.html";
                                
                            $snoopy->submit($submit_url,$submit_vars,$submit_files);


                            ?>
                        [COLOR=darkblue].: 1+1=23 :.[/COLOR]

                        Kommentar


                        • #13
                          Wie sieht es aus?

                          Hallo

                          seid Ihr weiter gekommen?

                          ich stehe nämlich vor dem gleichen Problem, mittels snoopy eine Datei zu senden ...

                          @ syco23: hast du ne Lösung gefunden?

                          Viele grüße, Björn

                          Kommentar


                          • #14
                            Nein, ich habe leider keine Lösung gefunden
                            [COLOR=darkblue].: 1+1=23 :.[/COLOR]

                            Kommentar


                            • #15
                              ich versuchs mal so: Wer mir so ein Script schreibt, bekommt 20 Euro auf sein Konto überwiesen. Ein Profi sollte das in ein paar Minuten hinbekommen, oder?
                              [COLOR=darkblue].: 1+1=23 :.[/COLOR]

                              Kommentar

                              Lädt...
                              X