Check alle échte Black Friday-deals Ook zo moe van nepaanbiedingen? Wij laten alleen échte deals zien

[php] Uploaded file bestaat niet

Pagina: 1
Acties:

Onderwerpen


  • Rekcor
  • Registratie: Februari 2005
  • Laatst online: 08-10 13:03
SOLVED
Mijn bestand-upload script werkt niet, maar ik begrijp niet wat er misgaat. Hier de relevante code:

PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
error_reporting(E_ALL);
print_r($_FILES);

//see if file exists
if(file_exists($_FILES['myfileinput']['tmp_name'])){
 echo ' File '.$_FILES['myfileinput']['tmp_name'].' does exist!';
}else{
 echo ' File '.$_FILES['myfileinput']['tmp_name'].' does NOT exist!';
}

//move the file
if (!move_uploaded_file($_FILES['myfileinput']['tmp_name'], 'mywritablefolder/mypicture.jpg')) {
 echo 'Could not move file!';
}


Dit geeft als resultaat:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Array
(
    [myfileinput] => Array
        (
            [name] => mypicture.jpg
            [type] => image/jpeg
            [tmp_name] => /tmp/phpWOvsyK
            [error] => 0
            [size] => 9483
        )

)
File /tmp/phpWOvsyK does NOT exist!
Could not move file!'


Ik krijg dus geen foutmeldingen, $_FILES['myfileinput']['error'] is netjes 0, maar het bestand /tmp/phpWOvsyK bestaat toch niet. Het staat ook niet in de /tmp folder.

Hoe kan dit?

  • zwippie
  • Registratie: Mei 2003
  • Niet online

zwippie

Electrons at work

Heb je in je form tag wel enctype='multipart/form-data' gezet?

How much can you compute with the "ultimate laptop" with 1 kg of mass and 1 liter of volume? Answer: not more than 10^51 operations per second on not more than 10^32 bits.


  • Rekcor
  • Registratie: Februari 2005
  • Laatst online: 08-10 13:03
Uiteraard :)

  • wackmaniac
  • Registratie: Februari 2004
  • Laatst online: 20-11 09:10
die tmp_name hoeft niet per se onder /tmp/* te staan:

http://www.php.net/manual...variables.files.php#89674:
code:
1
2
3
4
5
6
7
8
9
10
11
Array
(
    [file1] => Array
        (
            [name] => MyFile.txt (comes from the browser, so treat as tainted)
            [type] => text/plain  (not sure where it gets this from - assume the browser, so treat as tainted)
            [tmp_name] => /tmp/php/php1h4j1o (could be anywhere on your system, depending on your config settings, but the user has no control, so this isn't tainted)
            [error] => UPLOAD_ERR_OK  (= 0)
            [size] => 123   (the size in bytes)
        )
)


Afhankelijk van je settings kan die map dus ergens anders op je file system staan. Wellicht heb je wat aan is_uploaded_file.

[ Voor 13% gewijzigd door wackmaniac op 27-10-2011 14:37 ]

Read the code, write the code, be the code!


  • arendvw
  • Registratie: Juli 2010
  • Laatst online: 21-11 16:17
Is je map waar je 'm heen probeert te verplaatsen wel writable voor je webserver?

  • Rekcor
  • Registratie: Februari 2005
  • Laatst online: 08-10 13:03
Opgelost! Het was uiteindelijk een combinatie van schrijfrechten, een typo, een error-reporting instelling..

Bedankt!
Pagina: 1