创建一个文件夹,在那里有一个子文件夹与PHP

I've tried soooo many times now and I couldn't find a solution!

My problem:

I want users to be able to upload images in the folder "user_images" (this folder exists already on the server). The php script shall create a specific user subfolder in "user_images". Like this -> "user_images/user_65/(imagesGoHere)"

I tried it like that, but it doesn't work ->

$userid = $_SESSION['user_id'];
$folder = "user_".$userid;
$upload_dir = "user_images/.$folder";           
$upload_path = $upload_dir; 

if(!is_dir($upload_dir)){
mkdir($upload_dir, 0777);
chmod($upload_dir, 0777);
}

Would be nice if someone could help me! Thx

php
douxie9471
douxie9471 我是一个傻瓜!大声笑......谢谢你的帮助!我只需要添加一个/后面的文件夹$upload_dir=“user_images/$folder/”;酷吧!
接近 8 年之前 回复
dpfad62426
dpfad62426 好的...请快速帮助!将其更改为->$userid=$_SESSION['user_id'];$folder=“user_”。$userid;$upload_dir=“user_images/$folder”;$upload_path=$upload_dir;现在正在“user_images”中创建用户文件夹。但图像本身并没有存储在用户子文件夹中:(存储在“user_images/(图像)”中。任何想法为什么?
接近 8 年之前 回复
dqc19941228
dqc19941228 您正在尝试创建一个隐藏目录,更改此行,$upload_dir=“user_images/.$文件夹”;to$upload_dir=“user_images/$folder”;或$upload_dir=“user_images/”。$文件夹;
接近 8 年之前 回复
dongyingla8668
dongyingla8668 $upload_dir=“user_images/".$文件夹;也许这个?
接近 8 年之前 回复
dsf5632
dsf5632 将mkdir的第三个参数($recursive)设置为true,然后复制图像。
接近 8 年之前 回复

2个回答



你需要指定第三个参数,一个布尔值:</ p>

  mkdir($  upload_dir,0777,true); 
</ code> </ pre>
</ div>

展开原文

原文

You need to specify there third argument, a boolean:

mkdir($upload_dir, 0777, true);



如果PHP具有父目录中的特权,那么PHP只能创建目录。 作为一个警告,每个用户创建一个文件夹并不是一个特别可扩展的解决方案。</ p>

它不应该是递归的,创建后的chmodding是没有意义的,因为mkdir已经完成了。< / p>
</ div>

展开原文

原文

PHP can only create directories if it has the privileges in the parent directory to do so. As a word of warning, creating a folder per user is not a particularly scalable solution.

It shouldn't need to be recursive and chmodding after creation is pointless because mkdir does it already.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问