I have this piece of code that should create a random directory and move uploads there:
$uploadPath = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . mkdir( 'assets/post/email_uploads/{uniqid(attachment_)}', 0777 ) . DIRECTORY_SEPARATOR . $_FILES[ 'file' ][ 'name' ];
The path assets/post/email_uploads/ already exists so the random folder should go inside email_uploads. The issue I'm facing is what to place between the DIRECTORY_SEPARATORs and have everything work.
When I try mkdir( 'assets/post/email_uploads/{uniqid(attachment_)}', 0777 ) OR
mkdir( 'assets/post/email_uploads/'.uniqid(attachment_), 0777 ) - The folder is not created and the upload is placed at the root.
When I try
$attchmentPath = 'assets/post/email_uploads/';
$uploadPath = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . $attchmentPath.mkdir( uniqid(attachment_), 0777 ) . DIRECTORY_SEPARATOR . $_FILES[ 'file' ][ 'name' ];
OR
$attchmentPath = 'assets/post/email_uploads/';
$randomDir = mkdir( uniqid(attachment_), 0777 );
$newPath = $attchmentPath.$randomDir;
$uploadPath = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . $newPath . DIRECTORY_SEPARATOR . $_FILES[ 'file' ][ 'name' ];
The folder is created at the root instead of the desired path and the file is not uploaded at all.
Aucun commentaire:
Enregistrer un commentaire