uploadfile function not working

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
mcpalmer
Forum Newbie
Posts: 3
Joined: Mon May 15, 2006 6:55 am

uploadfile function not working

Post by mcpalmer »

Hi, having trouble with a file upload function i've created. This code works:

Code: Select all

$uploaddir = URL_SSFLASH;
$uploadfile = $uploaddir . $flashfile_name;

if (move_uploaded_file($flashfile, $uploadfile)) {
   $msg="File is valid, and was successfully uploaded.\n";
} else {
   $msg="Possible file upload attack!\n";
}
echo $msg;
I create a function that replicates this code:

Code: Select all

function uploadfiles($fileaddress, $filedest) {
	
	$filet=$filedest.$fileaddress_name;//set new destination

	if(move_uploaded_file($fileaddress, $filet)){
	
		return "File uploaded successfully";
	} else {
		return "Error uploading file";
	}
};
and use include at top of page to include file where function is and call function - i get these errors:

Code: Select all

Warning: move_uploaded_file(../swfsss/): failed to open stream: Is a directory in /home/screensa/public_html/adm/sys_func.php on line 14

Warning: move_uploaded_file(): Unable to move '/tmp/phpdDDcwK' to '../swfsss/' in /home/screensa/public_html/adm/sys_func.php on line 14
Error uploading file
what am i doing wrong here? Also using the $_FILE['flashfile']['tmp_name'] type format doesn't seem to work for me. For example $flashfile_name works fine but $_FILE['flashfile']['name'] does not. Any help much appreciated
BadgerC82
Forum Commoner
Posts: 25
Joined: Tue Feb 07, 2006 6:53 am

Post by BadgerC82 »

Could u include the make up of your function call?

Thanks
mcpalmer
Forum Newbie
Posts: 3
Joined: Mon May 15, 2006 6:55 am

Post by mcpalmer »

yes it is:

Code: Select all

$msg=uploadfiles($flashfile,$filedest);
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

try a print_r() of your $_FILES array within your function to make sure the array can be read inside your function.
mcpalmer
Forum Newbie
Posts: 3
Joined: Mon May 15, 2006 6:55 am

Post by mcpalmer »

ok, got it working now, i needed to use $FILES[][] format for function to see files properly. $FILES[][] wasn't working cos i was typing $FILE[][] instead! Its always the simplest things. I think i need a php editor!
Post Reply