Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] Upload zdjęcia
faflok
post 16.03.2008, 18:41:51
Post #1





Grupa: Zarejestrowani
Postów: 19
Pomógł: 0
Dołączył: 3.01.2008

Ostrzeżenie: (0%)
-----


Witam.

Wykorzytałem standardowe rozwiazania czyli formularz:

Kod
<form enctype="multipart/form-data" action="add.php" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="300000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>


I kod php w pliku add.php:

  1. <?php
  2. $uploaddir = '/domains/frak.com/public_html/werk/strona/photo/';
  3. $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
  4.  
  5. echo '<pre>';
  6. if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
  7. echo "File is valid, and was successfully uploaded.\n";
  8. } else {
  9. echo "Possible file upload attack!\n";
  10. }
  11.  
  12. echo 'Here is some more debugging info:';
  13. print_r($_FILES);
  14.  
  15. print "</pre>";
  16.  
  17. ?>


Ale pojawia się komunikat:

Kod
Possible file upload attack!
Here is some more debugging info:Array
(
    [userfile] => Array
        (
            [name] => foto.jpg
            [type] =>
            [tmp_name] =>
            [error] => 2
            [size] => 0
        )

)


Czy ktoś może wie gdzie tkwi błąd? Chmody ustawione na 777.
Powód edycji: Poprawiłem bbCode (ociu)
Go to the top of the page
+Quote Post
nospor
post 16.03.2008, 18:44:07
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




rety...
widzisz chyba ze tmp_name jest puste, widzisz ze error =2 to spojrz do manuala co to oznacza:
http://pl2.php.net/manual/en/features.file-upload.errors.php


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
faflok
post 16.03.2008, 20:56:33
Post #3





Grupa: Zarejestrowani
Postów: 19
Pomógł: 0
Dołączył: 3.01.2008

Ostrzeżenie: (0%)
-----


No OK masz racje. Tylko spokojnie bo to chyba przedszkole a ja dziś akurat ciężki dzień miałem.

Jeszcze tylko jedno pytanie:
Jak nadpisać istniejący plik?
np:
ktoś chce wgrac kolejne zdjęcie np: foto124.jpg ale to zdjęcie ma nadpisać istniejący plik foto.jpg i zachować nazwe foto.jpg?

Pewno proste ale ja już nie myśle. sleepysmiley03.gif
Go to the top of the page
+Quote Post
l0ud
post 16.03.2008, 21:42:02
Post #4





Grupa: Zarejestrowani
Postów: 1 387
Pomógł: 273
Dołączył: 18.02.2008

Ostrzeżenie: (0%)
-----


  1. <?php
  2. $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
  3. ?>


Zmienić basename($_FILES['userfile']['name']) na 'foto.jpg' (razem z apostrofami)


--------------------
XMPP: l0ud@chrome.pl
Go to the top of the page
+Quote Post
faflok
post 16.03.2008, 23:08:56
Post #5





Grupa: Zarejestrowani
Postów: 19
Pomógł: 0
Dołączył: 3.01.2008

Ostrzeżenie: (0%)
-----


Robiłem już tak wcześniej i oto błąd jaki wyskakuje:

Kod
Possible file upload attack!
Here is some more debugging info:Array
(
    [userfile] => Array
        (
            [name] => ganges.jpg
            [type] => image/jpeg
            [tmp_name] => /tmp/phpMYqRlV
            [error] => 0
            [size] => 12232
        )
)
Go to the top of the page
+Quote Post
Xniver
post 16.03.2008, 23:25:14
Post #6





Grupa: Zarejestrowani
Postów: 108
Pomógł: 26
Dołączył: 29.02.2008

Ostrzeżenie: (0%)
-----


Może nie masz odpowiednich CHMODów?
Go to the top of the page
+Quote Post
faflok
post 17.03.2008, 07:47:06
Post #7





Grupa: Zarejestrowani
Postów: 19
Pomógł: 0
Dołączył: 3.01.2008

Ostrzeżenie: (0%)
-----


CHMODy ustawione na 777

Ten post edytował faflok 17.03.2008, 07:47:34
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 05:18