I want to upload files with PHP and i use move_uplload_files to copy them to the destination folder I want, everything works fine with this :
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], './uploades/'))
die("success");
else
die("error");
But when I try this
$rand = chr(rand(97, 122)). chr(rand(97, 122)). chr(rand(97, 122));
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], './uploades/'.$rand))
die("success");
else
die("error");
I will get error, and it looks like move_uploaded_files can not create folders. How can I do this ?
Basically I am looking for a way to do it like file_put_contents()
that creates the path if not exist.
This works for me:
Use something like this:
is_dir()
checks if the folder is there.Use
mkdir()
.If you need to make multiple folders, such as by passing
a/b/c
, set the third argument toTRUE
.You can test if it is already there, and add if not like so....
Create the directory first using
mkdir()