473,396 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

PHP file upload form

Hello
I am trying to create a simple file upload form so my band members can
upload mp3s onto my server. I am using this tutorial:

http://www.tizag.com/phpT/fileupload.php
I am having problems creating the code for uploader.php. Can anyone
show me exacly how it should look?

Thanks

Jun 5 '06 #1
4 2597
I did this for the first time the other day.

On the HTML side:

<form enctype="multipart/form-data" action="/upload.php" method="POST"

Send this file: <input name="userfile" type="file" /> <br />
<input type="submit" value="Send File" />
</form>
And your PHP action:

$uploaddir = './dir/';
$file_name = $_FILES['userfile']['name'];
$uploadfile = $uploaddir . $file_name;
move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile);
If you're buying third party hosting, sometimes they have a maximum
file size which you'll want to watch out for.

Jun 6 '06 #2
Is this how my uploader.php file should look? Does the function spcript
go directly beneath the
php code? Thanks
-----------------------------------

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<title>Untitled Document</title>
</head>
// Where the file is going to be placed
$target_path = "uploads/";

/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename(
$_FILES['uploadedfile']['name']);
$_FILES['uploadedfile']['tmp_name'];

$uploaddir = './dir/';
$file_name = $_FILES['userfile']['name'];
$uploadfile = $uploaddir . $file_name;
move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile);
<body>
</body>
</html>

Jun 6 '06 #3
I think this is what you want:

<?php
$target_path = "./uploads/";
$target_path = $target_path .
basename($_FILES['uploadedfile']['name']);
move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path);
?>
It's a php page, so you don't want any html output. I'm assuming the
name of the files section of your form is "uploadedfile". Also, the
<form> tag should have the attribute
action="whatever_you_called_this_file.php". You really should learn how
these commands work using the PHP manual. Check out:
http://us3.php.net/manual/en/functio...oaded-file.php
http://us3.php.net/manual/en/features.file-upload.php
Both links offer great instruction and some tutorials.

Jun 6 '06 #4
Oh, and on my first example I forgot to close my first <form> tag with
the right bracket. Don't forget to close yours.
bj*******@hotmail.com wrote:
Is this how my uploader.php file should look? Does the function spcript
go directly beneath the
php code? Thanks
-----------------------------------

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<title>Untitled Document</title>
</head>
// Where the file is going to be placed
$target_path = "uploads/";

/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename(
$_FILES['uploadedfile']['name']);
$_FILES['uploadedfile']['tmp_name'];

$uploaddir = './dir/';
$file_name = $_FILES['userfile']['name'];
$uploadfile = $uploaddir . $file_name;
move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile);
<body>
</body>
</html>


Jun 6 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
2
by: mark | last post by:
How do I detect that a particular form element is a file upload or if the file upload has worked? In the Python cgi module documentation I found suggested code... form = cgi.FieldStorage()...
7
by: pbd22 | last post by:
hi. i am having probs understanding how to grab a file being uploaded from a remote client. i am using hidden input fields for upload such as: <input id="my_file_element" type="file"...
2
by: hotflash | last post by:
Hi All, I found the best pure ASP code to upload a file to either server and/or MS Access Database. It works fine for me however, there is one thing that I don't like and have tried to fix but...
6
Jacotheron
by: Jacotheron | last post by:
I need a PHP script that can upload music files (mp3). The script is for a home project I have started a while ago. I have a MySQL database of all the music that I have. Other computers on the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.