0

Tried many things but i can't get it working.

I have a sub directory with the name "pics" and i need to upload images there with my upload.php file.

How can i do this? Here is some of my code where i think i need to add the directory.

if(is_uploaded_file($_FILES['inputfile']['tmp_name'])){


    if(!file_exists($_FILES['inputfile']['name'])) {
        move_uploaded_file($_FILES['inputfile']['tmp_name'], $_FILES['inputfile']['name']);
    }

Thank you very much for your help.

Jordy
  • 150
  • 13

2 Answers2

0

Try this , you should place the folder at the correct root , i will assume that the php code is at the same folder. If not you need to direct the code to the right path. Finding your current path can be achived by using

echo __FILE__ ;

for example with your code i see that you dont place the path correct

So you mat try this..

$dir_name = '/pics';
if( move_uploaded_file($_FILES["files"]["tmp_name"], $dir_name) )
Meta_data
  • 558
  • 3
  • 14
0

You have to add the path when you do the check file exists and add path to destination file as well.

if (is_uploaded_file($_FILES['inputfile']['tmp_name'])) {

    $path = 'path/to/pics/';

    if (!file_exists($path . $_FILES['inputfile']['name'])) {

        move_uploaded_file($_FILES['inputfile']['tmp_name'], $path . $_FILES['inputfile']['name']);
    }
}
Mirceac21
  • 1,741
  • 17
  • 24