Click to See Complete Forum and Search --> : Uploading files to website
Jaime1985
01-19-2004, 04:27 AM
Hi everyone,
I want a user to to log onto our intranet site; and on a specefic webpage they go to they will have the facility to upload to my specified directory which i have put in the code.
All there needs to be is a form that has a browse function and an upload button. its just the code to that I'd like if someone can help..
thx
If your server supports PHP, search that section, as I know I've posted a script to do this, before.
Jaime1985
01-19-2004, 08:14 AM
Hi Pyro, I found your post:
<html>
<head>
<title>Upload a File</title>
</head>
<body>
<?PHP
$uploaddir = "uploads"; # must be chmoded to 777
if ($_POST['submit'])
{
$name = $_FILES['File']['name'];
$tmpname = $_FILES['File']['tmp_name'];
$size = $_FILES['File']['size'];
if (copy ($tmpname, "$uploaddir/$name"))
{
print ("File Name: $name<br/><br/>\n");
print ("File Size: $size<br/><br/>\n");
print ("Your file was successfully uploaded!<br/><br/>\n");
}
else
{
print ("Your file could not be uploaded.");
}
unlink ($tmpname);
}
?>
Upload a file to the server
<form action="upload.php" method="post" enctype="multipart/form-data">
File: <input type="file" name="File" size="20"><br/>
<input type="submit" name="submit" value="Upload File"></form>
</body>
</html>
I just can't see where the file will eventually be uploaded to on the server, do I have to change something?
Thanks
This line:
$uploaddir = "uploads"; # must be chmoded to 777
specifies which directory the files will be uploaded to. In this case, it will be uploaded to uploads, which must be a subdirectory of the directory that the upload script (upload.php) is in.
Jaime1985
01-19-2004, 10:09 AM
thx 4 your help, really appreciated.
I have one more question to ask,
I would like my users to download the files from the upload folder, is these a way of doing this?
i.e. Browse for the file and then push Download?
Im quite inexperienced with forms
thanks
You'll probably have to make a listing of all the files in the directory, and then use something like this (http://www.infinitypages.com/research/download.htm) to force the download.
BrainDonor
07-25-2005, 11:32 AM
Sorry for bumping a really old thread, but this script is great! Just what I've been looking for...although I do have one question. I know very little of PHP and was wondering whether the code can be changed to allow the user to name and/ or create (and chmod, I suppose) the directory in which they want to upload to? I know there are risks associated with this, but this is going to be for a couple of friends of mine to use for uploading images to host on my site.
*Edit: I just realized this is in the HTML forum. Sorry. :(
Kravvitz
07-25-2005, 02:22 PM
Yes, it's possible.
I suggest that you require a username and password to use a script like that though.
BrainDonor
07-25-2005, 02:27 PM
Yes, it's possible.
I suggest that you require a username and password to use a script like that though.
That's absolutely my intention. Okay, I'll go dig around in the PHP forum. thanks!
Tom