i want to create a folder on server using php and make it writable so tht i can upload files to it using form...
can someone help me with script on making folder and making it writeable on server.
thanx
i want to create a folder on server using php and make it writable so tht i can upload files to it using form...
can someone help me with script on making folder and making it writeable on server.
thanx
A few focused tips that build on what , and said: the two common causes for "mkdir works locally but not on the host" are (1) the path is wrong for that host and (2) the webserver/user lacks permission or the host restricts filesystem access. Since later reported it worked, it may have been a transient host-side issue — but the snippet below is a safer, repeatable approach for production.
// create an uploads folder next to this script, but do it safely
$dir = __DIR__ . '/uploads';
if (!is_dir($dir)) {
if (!mkdir($dir, 0755, true)) {
$err = error_get_last();
error_log('mkdir failed: ' . json_encode($err));
// handle failure (show friendly error / contact host)
} else {
chmod($dir, 0755); // adjust only if needed
}
}
if (!is_writable($dir)) {
error_log('Upload dir not writable: ' . $dir);
// fallback / notify admin
} Use absolute paths built from __DIR__ or $_SERVER['DOCUMENT_ROOT'] rather than guessing /htdocs/...; check existence with is_dir() and writability with is_writable() before creating or uploading, and catch failures with error_get_last() so you can log the precise warning. (php.net)
Security & troubleshooting notes: avoid making folders world-writable (0777) unless you understand the risks; prefer 0755 or 0750 and use server-side file validation. If PHP cannot create folders despite correct paths and perms, hosts sometimes enforce restrictions (open_basedir, chroot, or other limits) — check error logs or contact the host. (php.net)
Jump to Post— somedude3488 228Please at least google your question before posting here.
mkdir() is the function you are looking for.
Jump to Post— metaface 0You may also need to deal with permission issues. The web server typically runs as a different user (such as "nobody") than the user you use to manually create files/directories via FTP or command line.
If you create a directory with your PHP script, the owner will probably be …
Jump to Post— cwarn23 387thanx ... i did use mkdir ...with tht i m able to make the dir successfully on my harddisk while testing. ut on web server its not doing it ....cant figure out y plz help
here is my code
<?php mkdir ("/htdocs/lucky", 0777); echo " dir made successfully"; …
Please at least google your question before posting here.
mkdir() is the function you are looking for.
You may also need to deal with permission issues. The web server typically runs as a different user (such as "nobody") than the user you use to manually create files/directories via FTP or command line.
If you create a directory with your PHP script, the owner will probably be the web server user and not you. So in addition to reading about the mkdir() function, you might also want to read about chmod() to set permissions accordingly.
http://us2.php.net/manual/en/function.chmod.php
-Dave
thanx ... i did use mkdir ...with tht i m able to make the dir successfully on my harddisk while testing. ut on web server its not doing it ....cant figure out y plz help
here is my code
<?php
mkdir ("/htdocs/lucky", 0777);
echo " dir made successfully";
?> plz help
thanx ... i did use mkdir ...with tht i m able to make the dir successfully on my harddisk while testing. ut on web server its not doing it ....cant figure out y plz help
here is my code
<?php mkdir ("/htdocs/lucky", 0777); echo " dir made successfully"; ?>plz help
Well from that path specified, if it were on an online server it would look like if you have a dedicated server or same server configurations as your testing environment. When placing a / at the beginning of the path, it makes the location start from the beginning of the server root and usually there are a few folders it has to go through before getting to your account. I would suggest making a relative path to the script so for example, if the script was in your hompage or the same directory as your homepage then the following would apply:
<?php
mkdir ("lucky", 0777);
echo " dir made successfully";
?> its not working i did try that....i use a free server ...it has a folder htdocs within which i have to upload all the files like index or others.
its working ciary...it took i think server issue or something
thanx
usage of mkdir() is simplest option
i want to run application like c,c++ on my hosting server. plz tell me the solution...
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.