Page 1 of 1
Access Denied For One Script But Not The Other
Posted: Wed Oct 22, 2008 10:21 am
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?
Re: Access Denied For One Script But Not The Other
Posted: Wed Oct 22, 2008 10:31 am
by aceconcepts
Are you referencing from the root or local paths?
Re: Access Denied For One Script But Not The Other
Posted: Wed Oct 22, 2008 10:37 am
by watson516
local paths
Re: Access Denied For One Script But Not The Other
Posted: Wed Oct 22, 2008 10:41 am
by aceconcepts
Are the scripts literally identical?
Re: Access Denied For One Script But Not The Other
Posted: Wed Oct 22, 2008 10:47 am
by watson516
yes sir they are. Copied and pasted.
Re: Access Denied For One Script But Not The Other
Posted: Wed Oct 22, 2008 10:50 am
by aceconcepts
Lots of questions to answer...how lovely
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.
Re: Access Denied For One Script But Not The Other
Posted: Wed Oct 22, 2008 10:56 am
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.
Re: Access Denied For One Script But Not The Other
Posted: Wed Oct 22, 2008 11:10 am
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
}
}
Re: Access Denied For One Script But Not The Other
Posted: Wed Oct 22, 2008 11:19 am
by aceconcepts
Where's session_start()?
Re: Access Denied For One Script But Not The Other
Posted: Wed Oct 22, 2008 11:20 am
by watson516
In another file that includes both the func file and both script files.
Re: Access Denied For One Script But Not The Other
Posted: Wed Oct 22, 2008 11:22 am
by aceconcepts
uploadImage requires 3 parameters no?
Line 3 on "not working" script only supplies 2 parameters.
Re: Access Denied For One Script But Not The Other
Posted: Wed Oct 22, 2008 11:30 am
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
Re: Access Denied For One Script But Not The Other
Posted: Wed Oct 22, 2008 11:35 am
by aceconcepts
Well, this is as it states, a permission error.
Re: Access Denied For One Script But Not The Other
Posted: Wed Oct 22, 2008 11:37 am
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?
Re: Access Denied For One Script But Not The Other
Posted: Wed Oct 22, 2008 11:40 am
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.