Upload-Script [Datei wird nicht an den Server geleitet]

Hallo bplaced.net-Benutzer!

Ich versuche ein Upload-Script zu verwirklichen, doch das will mir überhaupt nicht gelingen. Offline (via XAMPP) funktioniert es einwandfrei, hier - überhaupt nicht :frowning:

upload.php

[code]

Select a file:
Upload File

[/code]

upload_file.php

[code]<?php
// Configuration - Your Options
$allowed_filetypes = array(’.jpg’,’.gif’,’.bmp’,’.png’); // These will be the types of file that will pass the validation.
$max_filesize = 524288; // Maximum filesize in BYTES (currently 0.5MB).
$upload_path = ‘/upload/’; // The place the files will be uploaded to (currently a ‘files’ directory).

$filename = $_FILES[‘userfile’][‘name’]; // Get the name of the file (including file extension).
$ext = substr($filename, strpos($filename,’.’), strlen($filename)-1); // Get the extension from the filename.

// Check if the filetype is allowed, if not DIE and inform the user.
if(!in_array($ext,$allowed_filetypes))
die(‘The file you attempted to upload is not allowed.’);

// Now check the filesize, if it is too large then DIE and inform the user.
if(filesize($_FILES[‘userfile’][‘tmp_name’]) > $max_filesize)
die(‘The file you attempted to upload is too large.’);

// Check if we can upload to the specified path, if not DIE and inform the user.
if(!is_writable($upload_path))
die(‘You cannot upload to the specified directory, please CHMOD it to 777.’);

// Upload the file to your specified path.
if(move_uploaded_file($_FILES[‘userfile’][‘tmp_name’],$upload_path . $filename))
echo ‘Your file upload was successful, view the file here’; // It worked.
else
echo ‘There was an error during the file upload. Please try again.’; // It failed :(.

?>[/code]

Apropos, hier ist der Link zum Tutorial (zymic.com/tutorials/php/crea … -with-php/)

Ich wäre euch echt dankbar!!

Gruß

Tja, mit “funktioniert ueberhaupt nicht” laesst sich leider ueberhaupt nichts anfangen.

Dem Script scheint derzeit allerdings jegliche Fehlerkontrolle zu fehlen - also solltest du eine solche zuerst mal einbauen. Wie’s geht, steht im PHP-Manual, Abschnitt Handling file uploads.

Kannst du mal eine URI zu deiner Datei posten?

[code]// Check if the filetype is allowed, if not DIE and inform the user.
if(!in_array($ext,$allowed_filetypes))
die(‘The file you attempted to upload is not allowed.’);

// Now check the filesize, if it is too large then DIE and inform the user.
if(filesize($_FILES[‘userfile’][‘tmp_name’]) > $max_filesize)
die(‘The file you attempted to upload is too large.’);

// Check if we can upload to the specified path, if not DIE and inform the user.
if(!is_writable($upload_path))
die(‘You cannot upload to the specified directory, please CHMOD it to 777.’);[/code]

Also das sind die nötigen “Fehlerkontrollen”:

  • Filetype
  • Filesize
  • Directory-Check

Beim Ausführen taucht “The file you attempted to upload is not allowed.” als Fehlermeldung auf, obwohl es eine png-Datei war, die auch nicht zu groß war.

Nein, sind es nicht.
Es koennen Fehler aufgetreten sein, bevor dein Script ueberhaupt in Aktion tritt.

Na dann fang mal an, zu Debuggen - Kontrollausgaben machen, etc.

Probier mal statt

if(!in_array($ext,$allowed_filetypes)) die('The file you attempted to upload is not allowed.');

if(!in_array($_FILES['type'],$allowed_filetypes)) die('The file you attempted to upload is not allowed.');

Du musst dazu jedoch $allwoed_filetypes noch etwas anpassen.

@ aschachinger
Habe das gerade ausprobiert, bringt aber nichts. Kann mir denn einer sagen, warum es offline via xampp läuft und hier nicht? Das verstehe ich nämlich überhaupt nicht??

Nein, die Dateien werden nicht an den Server geleitet, was ist das:
vrugaitis.bplaced.net/contact.php :ps: :ps:

$allowed_filetypes = array(’.jpg’,’.gif’,’.bmp’,’.png’);
evtl case-sensitiv? windows speichert als .PNG und .GIF

und Linux achtet ja auch sowas -> evtl weiß balmung da mehr zu

@ Hardi

habe die allowed_files editiert und noch erweitert. Bringt aber immer noch nichts … hmm !coffee

k.a. wo du das her hast, das ist jedenfalls Müll...richtig heißt es:
[code]<input type="submit" value="Datei hochladen!" />[/code]

k.a. wo du das her hast, das ist jedenfalls Müll…richtig heißt es:

Ich habe das auch schon probiert gehabt - hat auch nichts gebracht.

Nichts desto trotz muss es am Server liegen - offline (xampp; neueste Version) funktioniert es wunderbar!!

Darauf, dass du Kontrollausgaben machen sollst, um Wunsch (deine Annahme, welche Werte welche Variablen haben sollten) und Wirklichkeit miteinander abzugleichen, wurdest du bereits hingewiesen. Also, komm mal in die Poette …

Das ist def. kein Button zum absenden eines Formulars. Es kann sein, dass div. Browser es als solches verwenden (ähnlich dem Absenden mit Enter), was jedoch nicht im Standard definiert ist.

Lass man $_FILES ausgeben

Schau dir mal das Tutorial hier an.
Klick mich

@ lenz

so, ich habe nun dein Script verwendet, doch es gibt immer noch keinen Unterschied, d.h., dass es immer noch nicht funktioniert.

hat der ordner inwelchen du die dateien hochladen willst schreibrechte??

[quote=“vrugaitis”]@ lenz

so, ich habe nun dein Script verwendet, doch es gibt immer noch keinen Unterschied, d.h., dass es immer noch nicht funktioniert.

Nun stelle ich mir jedoch die Frage, wie es irgendjemand doch geschafft hat, einen Bild da hochzuladen!!! Dort taucht nämlich ein Bild auf, was ich noch nie gesehen habe …[/quote]

habe es mal ge testet und es es geht:

Warning: move_uploaded_file(upload/466.png) [function.move-uploaded-file]: failed to open stream: No such file or directory in /users/vrugaitis/www/upload_file.php on line 8

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/users/vrugaitis/temp/phpWVjIu4' to 'upload/466.png' in /users/vrugaitis/www/upload_file.php on line 8
Das Bild wurde Erfolgreich nach upload/466.png hochgeladen

mehr oder weniger…

(Das wahr mein Ava. hier ihm Forum :wink: )

Dir wurde bereits gesagt, dass “funktioniert nicht” verdammt noch mal keine brauchbare Problembeschreibung ist - also wieso kommst du immer noch mit so einem Bullshit an?

Was du stattdessen tun sollst, um dich der Problemursache zu naehern, wurde dir ebenfalls gesagt - aber das ignorierst du ja konsequent.

So, anscheinend liegt der Fehler am $_FILES. Es liefet nämlich kein Ergebnis an das weitere Script. Nun frage ich mich, wie ich das lösen kann? Oder warum bekommt $_FILES keine Informationen?