Access Denied For One Script But Not The Other

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
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Access Denied For One Script But Not The Other

Post by watson516 »

I am working on a website that allows users to upload images to their folder on the ftp server. I have several pages of the site that allows this uploading of different images, and on the first page I finished, everything works just fine. I copied the code over to the second page and kept everything the same but I get access denied. The scripts are being included into the same php file, they are located in the same directory and their destination directory are that same.

This is happening on my windows dev machine. The user folders were created with ftp_mkdir (or something similar to that) in php. I've checked the file permissions through the explorer and everything seems to be alright. Any ideas?
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Access Denied For One Script But Not The Other

Post by aceconcepts »

Are you referencing from the root or local paths?
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: Access Denied For One Script But Not The Other

Post by watson516 »

local paths
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Access Denied For One Script But Not The Other

Post by aceconcepts »

Are the scripts literally identical?
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: Access Denied For One Script But Not The Other

Post by watson516 »

yes sir they are. Copied and pasted.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Access Denied For One Script But Not The Other

Post by aceconcepts »

Lots of questions to answer...how lovely :D

If I were you i'd double check the destination path you're using to upload the images - in most cases this is the problem.
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: Access Denied For One Script But Not The Other

Post by watson516 »

the paths are the same.

I first attempted different paths because, well, if I didn't it would be pointless to have the second upload script. But when that didn't work, I thought it might have something to do with the fact that I created the dirs through the ftp command because I had never used it before. So, I switched the paths to the exact same thing as the other script that works (copy and paste) and I get the same error.

[edit]

I have created a function in a separate functions file that I use for both uploads. I pass the file name, the desctination dir, and, and another variable if I wish to rename the file upon upload. Same function. Calling the function with identical code and it doesn't work.
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: Access Denied For One Script But Not The Other

Post by watson516 »

Heres the code:

This is the calling of the function from the second (non-working) script.

Code: Select all

 
$target=$_SESSION['name']."/images/";
uploadImage($target,'photo1');
 
This is the calling of the function from the first (working) script.

Code: Select all

 
$target=$_SESSION['name']."/images/";
uploadImage($target,'logo','title_image');
 
And finally, this is the code for the function that uploads the file.

Code: Select all

 
function uploadImage($target,$file,$name=-1)
{
      switch($_FILES[$file]['type'])
      {
            case "image/png":
                   if($name==-1)
                   {
                        $filename=$_FILES['{$file}']['name'];
                        $target.=$filename;
                   }else{
                        $filename=$name.".png";
                        $target.=$filename;
                   }
            //etc
      }
      if(move_uploaded_file($_FILES[$file]['tmp_name'],$target))
      {
            //do stuff
      }
}
 
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Access Denied For One Script But Not The Other

Post by aceconcepts »

Where's session_start()?
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: Access Denied For One Script But Not The Other

Post by watson516 »

In another file that includes both the func file and both script files.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Access Denied For One Script But Not The Other

Post by aceconcepts »

uploadImage requires 3 parameters no?

Line 3 on "not working" script only supplies 2 parameters.
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: Access Denied For One Script But Not The Other

Post by watson516 »

aceconcepts wrote:uploadImage requires 3 parameters no?

Line 3 on "not working" script only supplies 2 parameters.
The third parameter is optional.

The exact error I get is..
Warning: move_upload_file(watson516/images/)[function...]: failed to open stream: Permission denied in C:\... on line 73
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Access Denied For One Script But Not The Other

Post by aceconcepts »

Well, this is as it states, a permission error.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Access Denied For One Script But Not The Other

Post by onion2k »

Off topic a bit, but what happens when I answer the phone in the middle of using the page for half an hour, the session expires and $_SESSION['name'] is no longer available?
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: Access Denied For One Script But Not The Other

Post by watson516 »

onion2k wrote:Off topic a bit, but what happens when I answer the phone in the middle of using the page for half an hour, the session expires and $_SESSION['name'] is no longer available?
If the session expires, they have to relogin.
Post Reply