mkdir() 不使用此代码为上传照片创建随机目录名称
mkdir() not working with this code for creating random directory name for upload photo
// profile picture upload
if (isset($_FILES['profilepic'])) {
if ( ((@$_FILES["profilepic"]["type"]=="image/jpeg")
|| (@$_FILES["profilepic"]["type"]=="image/png")
|| (@$_FILES["profilepic"]["type"]=="image/gif"))
&& (@$_FILES["profilepic"]["size"] < 1048576) ) //1 Megabyte
{
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$rand_dir_name = substr(str_shuffle($chars), 0, 15);
mkdir("userdata/profile_pics/$rand_dir_name");
这是我所有文件所在的目录:C:/xampp/htdocs/asweb
这是我要保存新目录的地方:C:/xampp/htdocs/asweb/userdata/profile_pics
我刚刚测试了以下内容:
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$rand_dir_name = substr(str_shuffle($chars), 0, 15);
echo $rand_dir_name.$b; // ojTxNHb0RuiyKze
mkdir("c:\dev\".$rand_dir_name,0777,TRUE);
它使 c:\dev\ojTxNHb0RuiyKze
没问题。我进去保存了一个文本文件。
手册 page 说
模式
The mode is 0777 by default, which means the widest possible
access. For more information on modes, read the details on the chmod()
page.
Note: mode is ignored on Windows. Note that you probably want to
specify the mode as an octal number, which means it should have a
leading zero. The mode is also modified by the current umask, which
you can change using umask().
但是在 linux 上,让它遵循 chmod 值。
编辑:op 做不到,我们再来一次:
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$rand_dir_name = substr(str_shuffle($chars), 0, 15);
echo $rand_dir_name.$b; // l1TGXW3kgQcr2N5
mkdir("C:\xampp\htdocs\asweb\userdata\profile_pics\".$rand_dir_name,0777,TRUE);
制作C:\xampp\htdocs\asweb\userdata\profile_pics\l1TGXW3kgQcr2N5
没问题
// profile picture upload
if (isset($_FILES['profilepic'])) {
if ( ((@$_FILES["profilepic"]["type"]=="image/jpeg")
|| (@$_FILES["profilepic"]["type"]=="image/png")
|| (@$_FILES["profilepic"]["type"]=="image/gif"))
&& (@$_FILES["profilepic"]["size"] < 1048576) ) //1 Megabyte
{
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$rand_dir_name = substr(str_shuffle($chars), 0, 15);
mkdir("userdata/profile_pics/$rand_dir_name");
这是我所有文件所在的目录:C:/xampp/htdocs/asweb
这是我要保存新目录的地方:C:/xampp/htdocs/asweb/userdata/profile_pics
我刚刚测试了以下内容:
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$rand_dir_name = substr(str_shuffle($chars), 0, 15);
echo $rand_dir_name.$b; // ojTxNHb0RuiyKze
mkdir("c:\dev\".$rand_dir_name,0777,TRUE);
它使 c:\dev\ojTxNHb0RuiyKze
没问题。我进去保存了一个文本文件。
手册 page 说
模式
The mode is 0777 by default, which means the widest possible access. For more information on modes, read the details on the chmod() page.
Note: mode is ignored on Windows. Note that you probably want to specify the mode as an octal number, which means it should have a leading zero. The mode is also modified by the current umask, which you can change using umask().
但是在 linux 上,让它遵循 chmod 值。
编辑:op 做不到,我们再来一次:
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$rand_dir_name = substr(str_shuffle($chars), 0, 15);
echo $rand_dir_name.$b; // l1TGXW3kgQcr2N5
mkdir("C:\xampp\htdocs\asweb\userdata\profile_pics\".$rand_dir_name,0777,TRUE);
制作C:\xampp\htdocs\asweb\userdata\profile_pics\l1TGXW3kgQcr2N5
没问题