Reputation: 135
Been trying to figure out why my $temp
file will not get placed in the $un
directory. The directory structure gets created but the temp file is not moved there. To verify a temp file is being created - if I remove the mkdir()
the temp file is added to uploads
folder
. How come the file is not being created in sub directory?
uploads/subfolder/
$temp = 'uploads/'.mkdir('uploads/'.$un) . md5($_FILES['image']['name']);
if (move_uploaded_file($_FILES['image']['tmp_name'], $temp)) {
// do something here..
}
Upvotes: 0
Views: 66
Reputation: 34914
Use like this,
mkdir('uploads/'.$un);
$temp = "uploads/$un/" . md5($_FILES['image']['name']);
Upvotes: 1
Reputation: 54841
As function mkdir
returns bool value, this line
$temp = 'uploads/'.mkdir('uploads/'.$un) . md5($_FILES['image']['name']);
is evaluated to
$temp = 'uploads/' . ('1' or '') . 'md5-filename';
So as you can see - your $temp
path will never store your $un
subdirectory.
The solution can be:
$temp = 'uploads/' . $un;
$res = mkdir($temp);
// check that folder created successfully
if ($res) {
$temp .= md5($_FILES['image']['name']);
// upload your file
}
Upvotes: 3