problem with upload script

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
mojobullfrog
Forum Newbie
Posts: 1
Joined: Wed May 28, 2008 12:34 am

problem with upload script

Post by mojobullfrog »

Hi there,

I'm trying to get a file uploader script to work. Ideally I'll be using a flash interface for multiple file uploading, but for the moment I'm starting with a simple single file uploader, which the user will access via a simple html page. This has been uploaded to my server but for some reason it's not working. I've checked with my hosting company to ensure that the permissions have been set correctly via their control panel, and it is world readable/writable.



The html form code looks like this:

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>



The PHP script looks like this:

<?php

$target_path = "clientuploads/";

$target_path = chmod($target_path . basename( $_FILES['uploadedfile']['name']), 0777);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}

?>



My main concern is with the php script and whether the permissions are correct (ie. chmod & 0777), and whether I've used the correct relative path for $target_path.


Ultimately I would like to use the php script to create a new directory path underneath "clientuploads" based upon their login details (ie. session data for username and password)

Something like this:

$company = $_SESSION['Company'];
$branch = $_SESSION['Branch'];


//what is the directory path I want to upload to?
$target_path = "clientUploads/"."$company/"."$branch/";

//create the directory (should have write permissons)
$old_umask = umask(0);
mkdir($target_path, 0777);
umask($oldumask);


Again, unsure about the correct relative path to use.

Any feedback about what could be preventing it from working would be welcomed.

Thanks.
Post Reply