PHP Upload to random dir.
I'm making an upload script with PHP
I want the uploaded files to be uploaded to a random directory.
I made something like this:
PHP Code:
// the important values
$randit = rand(100000, 999999);
$dir = "imgs/" . $randit . "/";
$uploadfile = $dir . $userfile_name;
if (mkdir("imgs/" . $randit) && chmod("imgs/" . $randit, 0777)) // make the dir
{
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
{
// file uploaded URL here
}
else
{
echo "Couldn't upload";
}
}
of course this isn't the whole script.. i wrote just the important parts of the script
after all of this i get "Couldn't upload", the dir was made with 0777 CHMOD but it didn't upload the file
what is my mistake ?