我希望有人可以帮助我如何将上传的文件存储在上传文件夹中的文件夹中..情况是当用户上传3个文件时,我希望它存储在他/她的文件夹中..让我们说< / p>
$directory="/upload/".$userID.";
当我删除$ userID部分时,它工作正常。
上传过程..
/*=======================File Upload Process============================*/
$num_files = count($_FILES['userfile']);
$saveDirectory = "upload/".$matricNo."/";
for($x =0; $x < $num_files; $x++)
{
$fileName = $_FILES['userfile']['name'][$x];
$tempName = $_FILES['userfile']['tmp_name'][$x];
$fileSize = $_FILES['userfile']['size'][$x];
$fileType = $_FILES['userfile']['type'][$x];
$allowed_ext = array ('doc','docx','pdf');
$file_ext = pathinfo($filename, PATHINFO_EXTENSION);
if (($_FILES['userfile']['size'][$x] > 1048576) && (in_array($file_ext, $allowed_ext) == false))
{
header('location: student_newSubmission2.php?error=6');
exit();
}
elseif ($_FILES['userfile']['error'][$x] == UPLOAD_ERR_OK)
{
$query3 = oci_parse($conn,"INSERT INTO upload(uploadID, uploadname, uploadtype, uploadsize, subID) VALUES (seq_uploadID.nextval,'$fileName', '$fileType', '$fileSize',$subID)");
$exe3 = oci_execute($query3) or die('Error, query failed');
if (move_uploaded_file($tempName, $saveDirectory.$fileName))
{
echo 'File Successfully Uploaded!';
}
else
{
echo 'There was an error whilst uploading the file.';
}
}
}
/*=======================File Upload End============================*/
答案 0 :(得分:4)
使用mkdir()
,默认情况下模式为0777,这意味着可以尽可能广泛地创建动态文件夹,
$saveDirectory = "upload/".$matricNo."/";
if(!is_dir($saveDirectory)){
mkdir($saveDirectory, 0777);
}
使用权限创建目录:
<?php
mkdir("/path/to/my/dir", 0700);
?>
语法:
bool mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context ]]] )
路径名:目录路径。
模式:默认情况下模式为0777,这意味着可以进行最广泛的访问。在Windows上忽略注意:模式。