Jump to content

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


MrMastermind

Recommended Posts

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]
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]

<?php

fupload($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.
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.