.... ok first off this might be in the wrong section... if so admin please move... second...
im looking to add an upload function to my website.... im looking for something simple that i dont have to code for myself...
i want a simple html page that has an browse and upload button that u select any file type and hit upload....
so example
upload website
http://www.mysite.com/uploader.html > browse > upload > http://www.mysite.com/upload1.html
on upload1.html i would like it to say congratulations your file has been uploaded adress is http://www.mysite.com/uploads/ioajsflk.file
and preferably when the file is uploaded it want it to hold the same name and if there is a file with a similar name to it just add a 2,3,4 etc. at the end....
i have ftp access to my website so i can do it that way...
in all... sorry if this is confusing im not on my computer and just trying to add this function but everything ive found is a bunch of php and stuff that i dont know and i keep running into dead ends....
ummmm upload help please... might be in the wrong section
Moderator: General Moderators
-
xxgraysonxx
- Forum Newbie
- Posts: 2
- Joined: Thu Nov 25, 2010 8:03 pm
Re: ummmm upload help please... might be in the wrong sectio
So something like this?
Note this was thrown together in a few minutes and so hasn't implemented file size limits, extension checking (eg. to forbid upload of .exe files), etc. Should be enough to get you started, though. Some recommended reading to help you build on it.
Code: Select all
<?php
$basedir = "http://www.yoursite.com";
if ($_FILES)
{
$file = basename($_FILES['uploadedfile']['name']);
$path = 'uploads/' . $file;
$ext = substr($file, strrpos($file, '.'));
$i = 1;
while (file_exists($path))
{
if ($i == 1)
{
$path = substr($path, 0, (strlen($path) - strlen($ext))) . $i . $ext;
}
else
{
$path = substr($path, 0, (strlen($path) - strlen($ext) - 1)) . $i . $ext;
}
$i++;
}
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $path))
{
$upload_path = htmlspecialchars(str_replace(' ', '%20', $path));
echo "The file has been uploaded and can be found at
<a href=\"$basedir/$upload_path\">
$basedir/$upload_path</a>";
}
else
{
echo "There was an error uploading the file";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>File Upload</title>
</head>
<body>
<form enctype="multipart/form-data" action="" method="post">
Choose a file: <input type="file" name="uploadedfile" />
<input type="submit" value="Upload" />
</form>
</body>
</html>-
xxgraysonxx
- Forum Newbie
- Posts: 2
- Joined: Thu Nov 25, 2010 8:03 pm
Re: ummmm upload help please... might be in the wrong sectio
ok the code is nice and clean... the only problem is i tried uploading a test file just a small .exe and it never showed up in the server....
Re: ummmm upload help please... might be in the wrong sectio
Does the uploads subdirectory exist? Is it writeable? The code I posted is tested and works.