PHP Test Directory writable

Source: Internet
Author: User
/**
* To test the writable nature of the directory
*
* @param string $dir
* @return int 1 writable 0 not writable
* Source DZ
* Xiao Jia (www.phpcina.cn) organized in 2006-06-26
*/
function Dir_writeable ($dir) {
/**
* $dir if not the directory will create a readable and writable directory
*/
if (!is_dir ($dir)) {
@mkdir ($dir, 0777);
}
if (Is_dir ($dir)) {//If the directory already exists
if ($fp = @fopen ("$dir/test.test", ' W ')) {//Create a file named Test.test to test
@fclose ($FP); Close file stream
@unlink ("$dir/test.test"); Delete test files
$writeable = 1; Can be created then the description can be read, the return value is 1
} else {
$writeable = 0; Cannot create, the return value is 0
}
}
return $writeable; return value
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.