Specify where to store upload files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Specify where to store upload files

Post by ljCharlie »

When uploading files to server, how do I specify which folder to store the files on the server?

ljCharlie
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the files are first stored in the temporary directories.. you then move them where you want them.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Indeed.

Google: [google]php file uploading snippet[/google]
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post by ljCharlie »

So then there is no way to specify the location where the file will be store then, correct?

ljCharlie
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you can specify it, however you do not control the filename it'll get saved as initially.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Yeah. You can specify a PHP temporary directory. But like feyd mentioned, it's best to have them stored in whatever temp directory PHP uses, and then move it to where ever you want.
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post by ljCharlie »

Okay. How do I specify the location? And can you explain the part about I do not control the file name?

Thank you,

ljCharlie
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Sami wrote:Google: [google]php file uploading snippet[/google]
Check out some samples from that search. :)
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Oh and the filename is a randomly generated name by PHP.

Upload a file and run this script:

Code: Select all

echo '<pre>';
   print_r ( $_FILES );
echo '</pre>';
And you will see it in action for yourself.
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post by ljCharlie »

What sort of permission should the folder be having to be able to receive the file? Currently the folder is set to 762 but I still error about permission denied.

ljCharlie
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

i believe they will need them all. 777 ( not sure hto.. but that most certenly will work )
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post by ljCharlie »

Will this be a security issue if it is set to 777?

ljCharlie
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Well u can have apache be set as owner of that folder, that would limit it somewhat, but what kind of problems do u expect. Or are u allowing exe files being uploaded on a windows server ? That is a security issue lol.
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post by ljCharlie »

Okay, here's another thing. How do I limit to only upload images such as jpeg file format?

ljCharlie
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you have to check the type of the file. Do not rely on the filename or mime-type sent by the browser, both can be faked. Check the actual type of the file using [php_man]getimagesize[/php_man] for more details.. I've posted many many times about this, so search for those.
Post Reply