【发布时间】:2015-01-08 15:08:53
【问题描述】:
帮助,我已经查看了这个问题的其他答案,但我似乎无法解决这个问题。
我想上传一张图片到目录 "uploaded_files/" 。 $user_id);
但是它给了我错误:
**move_uploaded_file() [function.move-uploaded-file]:copy() 函数的第二个参数不能是 /home/dawn01/public_html/wp-content/wordpresstheme/twentyten/new_uploads.php 中的目录第 27 行
PHP 警告:move_uploaded_file() [function.move-uploaded-file]:无法在 /home/dawn01/public_html/wp-content/themes/wordpresstheme/ 中将 '/tmp/phpkh4xzn' 移动到 'uploaded_files/76' new_uploads.php 第 27 行**
这是我的代码:
session_start();
$_SESSION['user_no'];
$startuplistingno = $_POST['startup_listing_no'];
//creating directory within uploaded files called user id
$dir = 'uploaded_files/'. $_SESSION['user_no'];
if ( !file_exists($dir) ) {
mkdir ($dir, 0744);
$temp = explode(".",$_FILES["file"]["name"]);
$newfilename = $_SESSION['user_no'];
move_uploaded_file($_FILES["file"]["tmp_name"],
"uploaded_files/" . $newfilename);
}
【问题讨论】:
-
mkdir($dir, 0744);可能不是您想要的。 *NIX 中的目录需要执行权限才能正常工作。管理员通常将0755用于公共目录(只有所有者拥有写入权限,其他人都可以读取),或0700用于私人目录(只有所有者拥有写入权限,其他人都无法读取)。 -
@amphetamachine,我完全同意,我什至在答案中提到了这一点。
标签: php file-upload