working with files

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
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

working with files

Post by Jr »

ok i have a little form that uploads files to a directory and I'm going to link it to a database when the file is uploaded but I need to get the file name, size, etc. Anyone know where I can get the functions (or whatver) for that?

This is the form:

Code: Select all

<form enctype=&quote;multipart/form-data&quote; action=&quote;upload.php?action=xxx&quote; method=&quote;post&quote;> <? //upload_send ?>
		<input type=&quote;hidden&quote; name=&quote;MAX_FILE_SIZE&quote; value=&quote;943718400&quote;>
			<? // Limit upload.php will POST is 900-MB but limit upload_send.php will actually send is only 3-MB ?>
		<p>Upload This File: <input name=&quote;userfile&quote; type=&quote;file&quote;>
		<input type=&quote;submit&quote; value=&quote;Upload&quote;>
	</form>
This is what I have for file size and stuff now but it returns wierd values for the name and just returns 'file' for file type.

Code: Select all

$file_name = basename("$userfile");
	$file_type = filetype("$userfile");
	$file_size = filesize("$userfile");
	$file_exists = file_exists("$userfile");
	// $delete_file = unlink("$userfile");
	
	print "<br>File Name: $file_name";
	print "<br>File Type: $file_type";
	print "<br>File Size: $file_size";
	print "<br>File Exists: $file_exists";
	// print "<br>File Removed: $delete_file";
...and one more thing... is the unlink() function the correct one to use to delete files from a directory?

Thanks for the help. Jr-

Jcart | Please review :arrow: Posting Code in the Forums
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

have a look at

Code: Select all

print_r($_FILES)
with the submitted form.
Post Reply