MrMastermind Posted October 23, 2006 Share Posted October 23, 2006 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?:[code] 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; } }[/code][code]//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); } } }[/code] Quote Link to comment Share on other sites More sharing options...
gmwebs Posted October 23, 2006 Share Posted October 23, 2006 Could you include the code where you call this function? Would like to see what you are passing in as $path and $file... Quote Link to comment Share on other sites More sharing options...
MrMastermind Posted October 23, 2006 Author Share Posted October 23, 2006 Sure, here's the code that's calling the function:[code]$path = "../_files-cms/Image";fupload($path, $_FILES['image']);[/code] Quote Link to comment Share on other sites More sharing options...
gmwebs Posted October 23, 2006 Share Posted October 23, 2006 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...[code]<?phpfupload($path, $_FILES['grafiek']);?>[/code]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. Quote Link to comment Share on other sites More sharing options...
MrMastermind Posted October 23, 2006 Author Share Posted October 23, 2006 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. Quote Link to comment Share on other sites More sharing options...
gmwebs Posted October 23, 2006 Share Posted October 23, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.