Solved

create directory with full permissions that will work in public server

Posted on 2010-11-23
15
256 Views
Last Modified: 2012-05-10
i'm creating a folder images with subfolders using the data

if (!mkdir($structure,'777', true) ) {
    die('Failed to create folders...');
}

the images folder is created and i can create a subfolder 20101122 for example which i can then get the files directory and display the images in there using xampp on my local machine, however when I upload it to my webserver, it fails to work.

if I try accessing the path via the browser i.e. ... images/20101122 it tells me I don't have access - permissions error. - what am I missing?

0
Comment
Question by:blue-genie
  • 8
  • 4
  • 2
  • +1
15 Comments
 
LVL 3

Assisted Solution

by:xeonol
xeonol earned 50 total points
ID: 34202646
The '777' will be recongized as a decimal number, see the reference of mkdir function http://php.net/manual/en/function.mkdir.php.

You may want to update the parameter of permission mode to use octal number:
mkdir($structure, 0777, true)

0
 
LVL 39

Author Comment

by:blue-genie
ID: 34202742
i used 0777 , i tried changing it to 777 because that's what it looks like in the folder properties, sorry I should have changed that before pasting it here. but changing to 0777 doesn't work either.
0
 
LVL 4

Expert Comment

by:betopa
ID: 34202810
I think maybe its because of the server configuration. You could not have the privileges needed.
Have you an admin user? You could check the permiissions in a shell window after you run your app on the web server. Even if you put the 0777 config, it could be creating it with another configuration.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 34202897
You probably need to be logged in like you are in FTP.  All of my PHP upload pages use FTP thru PHP to accomplish that.
0
 
LVL 39

Author Comment

by:blue-genie
ID: 34202899
yeah busy googling at the moment and seems to be something to do with apache access / privelages.

but there's hundreds of different suggestions and I have no clue . tried adding stuff to .htacess but that's not happening.
0
 
LVL 39

Author Comment

by:blue-genie
ID: 34202933
@DaveBaldwin - sorry I'm just a flash developer - what do you mean?
0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 100 total points
ID: 34202945
See the user notes here: http://php.net/manual/en/function.mkdir.php  You can still have problems because the PHP/web process doesn't run under your user.  It runs under the user for Apache.  Which of course doesn't mean anything under Windows but it does on Linux.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 39

Author Comment

by:blue-genie
ID: 34203033
ok cool that looks promising. will need to wait till I get home to test properly (with the webcam) will revert to you asap.
tx.
0
 
LVL 4

Expert Comment

by:betopa
ID: 34205189
On the other side, it could be dangerous to mess with the apache user and security configurations.

You probably dont need to see the folder through the url in the browser, but you could do a script to display them. Watch this, specially the 2nd method:

http://www.mysql-apache-php.com/fileupload-security.htm
0
 
LVL 39

Author Comment

by:blue-genie
ID: 34214143
hey guys still no joy.
please have a look at the code attached, where do i put the chmode (bearing in mind i'm not a php developer) - this file is a combination of various tutorials ... this works in xampp on my machine, however on various live servers, the permissions aren't working. I chatted with my service provider and I have to overwrite it, and apparently Chmod is the way, but I can't get it to work ...

@betopa - in terms of security etc - thanks for that. Will definately point it out to the server admin guys.

 
<?php


$uid = $_GET[uid];
$structure = './images/' .  date("Ymd") .'/' . $uid. '/';

if(is_dir($structure))
{
echo "Already exists!";
}
else
{
echo "Doesn't exist" ;

if (!mkdir($structure,'0777', true) ) {
    die('Failed to create folders...');
}
} 


if(isset($GLOBALS["HTTP_RAW_POST_DATA"])){
	$jpg = $GLOBALS["HTTP_RAW_POST_DATA"];
	$img = $_GET["img"];
	$filename = 'images/' . date("Ymd"). "/" .$uid. "/img_". mktime(). ".jpg";
	file_put_contents($filename, $jpg);
} else{
	echo "Encoded JPEG information not received.";
}
?>

Open in new window

0
 
LVL 4

Accepted Solution

by:
betopa earned 350 total points
ID: 34215116
You are welcome.
Now, about the solution the ISP chat-guy gave you:
It is just not posible!
I dont think that the guy from the chat made a good job helping you.
You cant "cheat" admin privileges (or at least it is not THAT EASY). Your code is fine! But the folder will always be created with YOUR limitations defined by the server admin...

I strongly recomend a php script that displays what I think you want, the way you want it.
You could read the folder files, and print them in the browser:

<?php

if ($handle = opendir('/path/to/files')) {
    echo "Directory handle: $handle\n";
    echo "Files:\n";

    /* This is the correct way to loop over the directory. */
    while (false !== ($file = readdir($handle))) {
        echo "$file\n";
    }

    /* This is the WRONG way to loop over the directory. */
    while ($file = readdir($handle)) {
        echo "$file\n";
    }

    closedir($handle);
}
?>
0
 
LVL 4

Assisted Solution

by:betopa
betopa earned 350 total points
ID: 34215130
Sorry, the specs of the function:

http://php.net/manual/en/function.readdir.php
0
 
LVL 39

Author Comment

by:blue-genie
ID: 34215454
betopa, just so that i understand, you mean to keep the php code as is and use that code you provided now to access it?
i'll have to try it over the weekend. thanks.
0
 
LVL 39

Author Comment

by:blue-genie
ID: 34221916
betopa i can't get this to work.
please help!
i get as far as writing the folder, can't get into the folder on my webserver to write to it or read to it.

0
 
LVL 39

Author Comment

by:blue-genie
ID: 34226288
ok all i manged to get it right. it was a case of my logic failed in terms of overwriting existing folders etc. and i also needed to use chmod.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now