Reputation: 19
I am creating an apps for uploading file into the system but here, i am facing a problem. the folder have been create properly as i want but when i click the upload button, the file is not save in the folder as i set as a target.. below is my syntax.
$id=$_SESSION['topic'];
$target_path = mkdir("doc_student/$id", '0777');
$target_path = $target_path . basename($_FILES['uploadedFile']['name']);
if(move_uploaded_file($_FILES['uploadedFile']['tmp_name'], $target_path)){
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}else{
echo "Error during uploading this file";
}
Upvotes: 0
Views: 81
Reputation: 22711
mkdir() Returns TRUE on success or FALSE on failure. if you assign $target_path
to mkdir
function then variable becomes boolean. Try this,
$target_path = "doc_student/$id";
if(!is_dir($target_path)){
mkdir($target_path, '0777');
}
instead of
$target_path = mkdir("doc_student/$id", '0777');
Upvotes: 2
Reputation: 525
mkdir()
retuns a boolean
if it has success, not the created folder's path, you must use another syntax:
mkdir("doc_student/$id", '0777');
$target_path = "doc_student/$id";
Upvotes: 1