Contact Us Forum Rules Search Archive
WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-26-2004, 09:32 PM
WebProWorld New Member
 

Join Date: Aug 2003
Location: Great Lakes Region, USA
Posts: 14
kender RepRank 0
Default php file upload script

i have a script for my users to upload files to my server...

the upload directory is chmod to 777 and files upload properly.

the only trouble is that I am having trouble getting it to verify if a filename is in use or not, it just overwrites the file regardless, can someone take a look and tell me what i'm missing?

here is the code
Code:
$file_dir = "./files";

foreach($_FILES as $file_name => $file_array)
{
	echo "Creating temporary file..... ".$file_array['tmp_name']."
\n";
	echo "Checking file name: ".$file_array['name']."
\n";
	echo "File type: ".$file_array['type']."
\n";
	echo "File size: ".$file_array['size']."

\n";

	if (is_uploaded_file($file_array['tmp_name']))
	{
		move_uploaded_file($file_array['tmp_name'], "$file_dir/$file_array[name]")
		or die ("Couldn't copy, file name already in use.");
		echo "File was moved successfully.
";
	}
}
this is based off of sams teach yourself php books script
all works except the verifying a filename
__________________
webmaster
Kender Internet Kompany
Reply With Quote
  #2 (permalink)  
Old 03-27-2004, 11:16 AM
WebProWorld New Member
 

Join Date: Aug 2003
Location: Great Lakes Region, USA
Posts: 14
kender RepRank 0
Default

Never mind, added this bit of code, and got it working fine!

thanks for looking though

Code:
if (file_exists("$file_dir/$file_array[name]")) 
{
   echo "Couldn't copy.
File name (<font color=navy>".$file_array['name']."</font>) already in use.
Please rename file and attempt upload again.";
} 
	else 
	{
__________________
webmaster
Kender Internet Kompany
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: , , ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0