2012-01-08 133 views
0

我的代码一直说这个文件夹不存在,虽然它应该由mkdir函数检查..它创建文件夹,但不经过上传过程..和在无法找到文件夹上显示错误..算法是否正确?请帮助..您的建议将有所帮助! :)文件系统路径创建错误(文件上传)

这里是代码..

if(!(file_exists($target_path))) 
{ 
    if(!mkdir($target_path, 0777, TRUE)) 
    { 
     die ("could not create the folder on mkdir"); 
    } 
    //in this line the error occurs..printing what is below..// 
    die ("could not find folder on file exists"); 
} 
else 
{ 
    umask($target_path); 
    ... 
} 
+0

您能引用确切的错误消息以及它们出现在哪些行上吗? – 2012-01-08 13:15:51

+0

@Pekka我已经.. ..请看看..谢谢..:D – SimonCode 2012-01-08 13:18:53

+0

感谢编辑@hakre hehe ..:D不知道怎么说.. – SimonCode 2012-01-08 13:22:53

回答

1

file_exists()日常需要完整的文件路径类似

/var/www/uploads/file1.c 

所以

file_exists($target_path); 

调用就可以了。但第二次调用创建目录,即

mkdir() 

是需要一个目录,而不是一个文件的路径,即,它需要在/ var/WWW /上传只是一部分。 因此您可以从路径名中删除基名并将其应用于mkdir函数()

1

尝试..

如果(file_exists($ target_path)& & is_dir($ target_path)){//代码的其余部分。 .. }

的,而不是...

如果(!(file_exists($焦油get_path))){

}

希望这会为你做些什么......

...................... .........

一件事...... 我认为这个问题是如果(!(file_exists($ target_path))){}声明,

这应该是... if(!file_exists($ target_path)){}

+0

好吧,我会尝试这个.. – SimonCode 2012-01-08 13:42:57

+0

它仍然没有工作.. – SimonCode 2012-01-08 13:58:42

2

在文件上传过程中,您的文件保存路径move_uploaded_file() 功能可能会产生问题。我说的可能是因为你给出的代码对我来说不够清楚。 move_uploaded_file()的第二个参数是第一个参数是文件名的目的地。请检查$ target_path的值,它可能会解决您的问题。谢谢。

+0

感谢您的帮助! :d – SimonCode 2012-01-08 16:32:41