【发布时间】:2011-07-25 22:19:22
【问题描述】:
我的代码如下所示:
do
{
$rand = rand(1,10000000);
$name_of_file_clear = $rand ;
$name_of_file = $rand . '.JPG' ;
$name_of_file_t = $rand . '_t.JPG' ; // for thubnsdffafasf
$this_directory_path = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
$images_directory_path = $_SERVER['DOCUMENT_ROOT'] . $this_directory_path . 'img/' . $name_of_file_clear . '/';
$whole_path = $images_directory_path.$name_of_file;
} while (file_exists($whole_path));
mkdir($images_directory_path, 777);
chmod($images_directory_path, 777);
move_uploaded_file($temp_file_name, $whole_path);
问题是,当我尝试上传文件时,文件没有上传。我认为问题出在权限上。请帮助我,我是php新手。
【问题讨论】:
-
如果启用
error_reporting&display_errors,PHP会告诉你是否是权限问题... -
而不是 think 问题出在权限上,PHP 会告诉你它试图写入哪个路径,以及为什么它不能写入那里。所以,是的,这会对你有所帮助。如果您在开发时没有显示 PHP 试图向您展示的如此有用的错误,那么您不仅会妨碍自己,甚至可能会发现其他人不愿意提供帮助,除非您向他们展示您的实际错误。
-
我发现了这个网站snippets.dzone.com/posts/show/1718 我不明白如何让它显示错误?我应该把它放在哪里?
-
sn-p 可以在你的代码的最开始。但是,它无法捕获解析错误,因此更好的是(在使用 apache 和启用 .htaccess 时)在您的
.htaccess中添加以下 2 行:php_value error_reporting 32767和php_flag display_errors on。 -
好的,我试试这个,我真的不知道 apache 和 htaccess 是什么,但我会去网上看看