我目前正在研究 raywenderlich.com 团队的iOS6 By Tutorials 的Passbook部分,并且在我的 PHP 中遇到以下错误:
警告:mkdir() [function.mkdir]: File exists in /xxx/xxx/xxx/xxx/Pass.php on line 26
警告:mkdir() [function.mkdir]: File exists in /xxx/xxx/xxx/xxx/Pass.php on line 26
警告:rmdir(/tmp/50c8d11c60538/..) [function.rmdir]: Directory not empty in /xxx/xxx/xxx/xxx/Pass.php on line 54
我的课程中的代码如下:
class Pass
{
private $workFolder = null;
private $ID = null;
var $content = null;
var $passBundleFile = null;
private function copySourceFolderFilesToWorkFolder($path)
{
// recurse over the contents and copy files
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path),
RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $name => $fileObject)
{
if (is_file($name) && substr($fileObject->getFileName(), 0, 1) != ".")
{
copy($name, $this->workFolder."/".str_replace($path."/", "",$name));
}
else if (is_dir($name))
{
mkdir($this->workFolder."/".str_replace($path."/", "",$name));
}
}
}
// delete all auto-generated files in the temp folder
function cleanup()
{
// recurse over conrents and delete files
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($this->workFolder),
RecursiveIteratorIterator::CHILD_FIRST);
foreach ($files as $name => $fileObject)
{
if (is_file($name))
{
unlink($name);
}
else if (is_dir($name))
{
rmdir($name);
}
}
rmdir($this->workFolder);
}
function __construct($path)
{
assert(file_exists($path."/pass.json"));
$this->ID = uniqid();
$this->workFolder = sys_get_temp_dir()."/".$this->ID;
mkdir($this->workFolder);
assert(file_exists($this->workFolder));
$this->copySourceFolderFilesToWorkFolder($path);
$this->readPassFromJSONFile($this->workFolder."/pass.json");
}
// cleanup the temp folder on object destruction
function __destruct()
{
$this->cleanup();
}
}
我正在实例化一个实例:
$coupon = new Pass("pass/source");
我已经尝试上传随本书提供的示例代码并得到相同的错误。
我已经在相关论坛上发布了这个,但是还没有人回复,并且想在继续之前深入了解这个。
谢谢,尼克