Jump to content


Photo

Upload file script works directly in script, but not as function


  • Please log in to reply
5 replies to this topic

#1 MrMastermind

MrMastermind
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 23 October 2006 - 08:37 AM

Hi,

I have this simple script that uploads a file. I thought I'd write it into a function, so I could call it more easily. But when I use the function I get a permission denied error, while the script works perfectly when it is directly in the other script. Can anyone tell me why?:

	function fupload ($path, $file){
				//Upload grafiek naar server				
				if (trim($file['name'])!=""){ 
					$newfile			= $file['name']; 
					$filename_tmp	= $file['tmp_name']; 
					$grafiek			= $file['name'];
				
					if (is_uploaded_file($filename_tmp)){
						$save_loc = $path . $newfile;
			
						// Move the Uploaded file to the correct Directory
						if(move_uploaded_file($filename_tmp, $save_loc)){
							chmod("$save_loc",0777);
						}
					}
				}else{
			return $curfile;
		}
	}

//Upload grafiek naar server
				$file_dir  = "../_files-cms/Image/";
				
				if (trim($_FILES['grafiek']['name'])!=""){ 
					$newfile			= $_FILES['grafiek']['name']; 
					$filename_tmp	= $_FILES['grafiek']['tmp_name']; 
					$grafiek			= $_FILES['grafiek']['name'];
				
					if (is_uploaded_file($filename_tmp)){
						$save_loc = $file_dir . $newfile;
			
						// Move the Uploaded file to the correct Directory
						if(move_uploaded_file($filename_tmp, $save_loc)){
							chmod("$save_loc",0777);
						}
					}
				}


#2 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 23 October 2006 - 08:51 AM

Could you include the code where you call this function? Would like to see what you are passing in as $path and $file...

#3 MrMastermind

MrMastermind
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 23 October 2006 - 09:32 AM

Sure, here's the code that's calling the function:

$path = "../_files-cms/Image";

fupload($path, $_FILES['image']);


#4 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 23 October 2006 - 10:03 AM

Have you just translated the 'grafiek' to 'image' for the purposes of this post? If not, then that is a difference already. I would have expected...


<?php

fupload($path, $_FILES['grafiek']);

?>


Even so, I seem to remember having problems with this kind of thing in the past too. I had to break down the troubleshooting into stages - check the variables, check the temp file gets created, etc.

#5 MrMastermind

MrMastermind
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 23 October 2006 - 10:18 AM

Yes, sorry about that, I translated the variable for this forum. I can see the temp file gets created and the variables also match up. So I still haven't got a clue why this is not working.

#6 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 23 October 2006 - 10:23 AM

So is it failing on the move part of the function then? Are you using 2 separate scripts i.e. working.php and notworking.php? Check that the notworking.php script has permission to do what you are trying to do. Might be to do with the owner of the save location? If you are using 2 scripts, try putting the function into the working one.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users