Re: php4 and writing binary

Tim Oliver Wagner <[email protected]>
Newsgroups gmane.linux.suse.programming
Message-ID <[email protected]>
Am Mittwoch, 16. März 2005 01:54 schrieb Bodo Kaelberer:
> Du hast das Lesen vergessen. $x enthält ein Resource-Handle (was als
> Text ausgedrückt etwas wie "Resource idä #...." ergibt. Und diese
> Zeichenkette schreibst Du in die zweite Datei.
> Was Du aber wirklich schreiben willst, ist der binäre INHALT des
> Bildes. Und dazu musst Du von $x lesen.

Ah, Vielen Dank! Das war die Lösung.

Ich dachte das würde PHP automatisch erkennen ... bin wohl von JAVA etwas 
verwöhnt ... :-(

> Am besten wohl mit:
>     $inhalt   = fread( $x, 1000000 );
> oder mit einer kleineren Blockgrösse in einer Schleife.
>
> Und $inhalt schreibst Du dann nach $y, wie oben.

klappt prima.

Jedoch verstehe ich nicht warum es geht mit:
    $handle = fopen("http://foo.de/bar.jpg", "rb");
    $y = fopen(getcwd() . "/files/foobar.jpg", "wb");
    while (!feof($handle)) {
        $x .= fread($handle, 8192);
    }
    if (!fwrite($y, $x))
        echo "schreiben nicht erfolgreich!";
    else
        echo "schreiben erfolgreich!";
    fclose($y);
    fclose($handle);

und nicht auch mit:
    $handle = "http://foo.de/bar.jpg", "rb";
    $y = getcwd() . "/files/foobar.jpg", "wb";
    copy ($x, $y);

Auf meinem Rechner hier local funktioniert das copy auch prima. Jedoch 
funkioniert es leider nicht auf dem Webserver ... :-(

Dies verstehe ich jedoch nicht ... denn wenn das eine funktioniert, dann 
sollte das Andere doch auch funktionieren. Zumal es ja auch local 
funktioniert.

Kennt jemand einen Grund für dieses Verhalten?

tia

Oli

-- 
Um die Liste abzubestellen, schicken Sie eine Mail an:
    [email protected]
Um eine Liste aller verfügbaren Kommandos zu bekommen, schicken
Sie eine Mail an: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.