0

I have a folder structure like this:

etc
files
public_html
tmp

I want users of my website to be able to upload files, and have those files stored inside the files folder (as opposed to storing them inside some folder within public_html). This is for security reasons. I'm a bit of a newbie, and I'm having trouble figuring out how to store the uploaded file to the files folder. Here is my code (the relevant part?):

$path = dirname( __FILE__ ) ."/" . 'files/my_file.pdf';
$success = move_uploaded_file( $tmp_name, $path );

How should I change $path to get this to work?

Aaron Brokmeier
  • 41
  • 1
  • 2
  • 8

2 Answers2

1

It is hard to say where you files are being uploaded to with knowing what the value for FRAMEWORK_PATH is. If you specifically want to put a file to the location of your choosing just specify it explicitly like:

$path = '/path/to/files/';
$filename = 'name_you_want_to_give_upload';

$success = move_uploaded_file($tmp_name, $path . $filename);
Mike Brant
  • 70,514
  • 10
  • 99
  • 103
  • 2
    OP should also make sure that the directory he/she wishes to upload to is writeable by their web server. – doremi Oct 27 '12 at 00:42
1

If you want to save a file outside where your upload.php files is, then you need to add ../ at the beaning of the file path where you wanna save it, eg:

if your upload.php files is in this root:

public_html/files/php/upload.php

but, your want to save your uploaded files on a folder which name is upFiles and it is outside the php folder (which is this case), you may write the path like this:

../upFiles/

You can use this method if you want to save it on a sub-folder too:

../files/anotherFolder/upFiles
Melvin Guerrero
  • 342
  • 3
  • 10