0

Hello,
I am looking for a few things...
1. How to put an upload field into a web page to that I can upload files to a directory on server.
2. I want to be able to choose different directories to upload it to (clients)
3. I would like to have it email that client that their file has benn updated.

I have a session that is based of the clients username when logging in. If that helps.

Thank you,
Tim

2
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by SuntechWebsites
0

The upload form works great. I need to take it a step further.
I have a site with different clients. Each client has a directory where their files are stored.
How can I make this script upload files to a specific user drirectory?

This is the form:
<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>

This is the current script that uploads to only one specific directory called upload:
<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
?>


<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
}
else
{
echo "Invalid file";
}
?>


<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>

0

hello,
umm first off, w3schools teaches you things step by step, so you will only need the last php code, not all 3..lol.. second, what i would have done is when the user creates there profile, it would also create a folder in a directory where the folder would be called there username. this way, when the user logs in and uses the upload form, they would have there session going and u can use it to define the folder.

$user = $_SESSION['myusername'];
move_uploaded_file($_FILES["file"]["tmp_name"],
"$user/" . $_FILES["file"]["name"]);

But like i said, this is just a rough idea to get the ball rolling. i hope this helps

0

That is what I do from the client side, but I should have stated that I want to do this part from an "admin" side, not for the clients. I want to choose wich one I want to upload to.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.