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]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.