[SOLVED] Upload file

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
S_henry
Forum Contributor
Posts: 148
Joined: Sun Jan 25, 2004 10:25 pm
Location: M'sia

[SOLVED] Upload file

Post by S_henry »

Hi guys.. In my PHP web-based system, I want to do one part that can upload file into the folder. For example, in this system, there are one page to register user. In this page I can enter all user profiles. Then I can upload user's photo and I want to save/upload this photo into one folder called 'photo'. I run this system on my server using Centos as my Operating System. The problem now is I don't know the code to upload file into the folder. Anybody can help me please?
Last edited by S_henry on Fri Mar 30, 2007 2:18 am, edited 1 time in total.
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

Use a HTML upload form and then you'll need to look into http://uk.php.net/manual/en/function.mo ... d-file.php
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Also, be aware that the "type" information sent to php is entirely user controlled and therefore completely unreliable. You must do your own checks to ensure the file is a type you are wanting to accept.
S_henry
Forum Contributor
Posts: 148
Joined: Sun Jan 25, 2004 10:25 pm
Location: M'sia

Post by S_henry »

Now I can upload file into the folder. But its only work on Windows. When I put the system into the Centos server, it won't work. I can use two functions for this and both work on Windows. These are the funtions:

Code: Select all

move_uploaded_file($filename,$uploadpath."/".$filename_name);
//or
copy($filename,$uploadpath."/".$filename_name);
Anybody have any idea on this please?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

you must chmod() the destination folder to give it the correct permissions
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
S_henry
Forum Contributor
Posts: 148
Joined: Sun Jan 25, 2004 10:25 pm
Location: M'sia

Post by S_henry »

OK. Now solved. Thanks guys. :D
Post Reply