Solved

create directory with full permissions that will work in public server

Posted on 2010-11-23
15
258 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

840 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