Page 1 of 1

uploading file into a directory

Posted: Tue Sep 08, 2009 11:39 pm
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!

Re: uploading file into a directory

Posted: Wed Sep 09, 2009 9:26 am
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.

Re: uploading file into a directory

Posted: Wed Sep 09, 2009 8:02 pm
by agent007marc
I got it already. Thanks!