uploading file into a directory

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

Post Reply
agent007marc
Forum Newbie
Posts: 3
Joined: Tue Sep 08, 2009 11:37 pm

uploading file into a directory

Post by agent007marc »

hi! i'm new in php and I'd like to know what's the correct code for adding a file into a directory. The file is from a form and you have to select a directory in the form where to add it. I used this code:

$uploadDir = '../site/photos/'$_POST['albums']'';


if(isset($_POST['submit']))
{
$fileName = $_FILES['image1']['name'];
$tmpName = $_FILES['image1']['tmp_name'];
$fileSize = $_FILES['image1']['size'];
$fileType = $_FILES['image1']['type'];



$filePath = $uploadDir.$fileName;

$result = move_uploaded_file($tmpName, $filePath);

but it's not working.

Thanks!
SikoSoft
Forum Newbie
Posts: 6
Joined: Wed Sep 09, 2009 9:16 am

Re: uploading file into a directory

Post by SikoSoft »

Are you sure the directory is "writable"? On *nix systems this means either making the directory owned or a part of the user group that the web server daemon runs as, or simply using CHMOD 0777 on the folder (though, I'd argue that this is less secure, but you don't have much of a choice if you are on shared hosting).

Perhaps you should display errors so you can get any output from PHP.
agent007marc
Forum Newbie
Posts: 3
Joined: Tue Sep 08, 2009 11:37 pm

Re: uploading file into a directory

Post by agent007marc »

I got it already. Thanks!
Post Reply