文件上传路径动态问题

I need to upload file . I get a value as dynamic value Im using angular js also.

$reg =  "<script>document.write(localStorage.getItem('regNo'));</script>";

Am getting correct value for $reg.

$uploadPath = dirname( __FILE__ ) . DIRECTORY_SEPARATOR .'Folder1/folder2/'. $reg. DIRECTORY_SEPARATOR . $_FILES[ 'file' ][ 'name' ];

But by using this, my file is not getting uploaded.

But if I use the below code (If $reg = img1), it will be a success.

$uploadPath = dirname( __FILE__ ) . DIRECTORY_SEPARATOR .'Folder1/folder2/img1'. DIRECTORY_SEPARATOR . $_FILES[ 'file' ][ 'name' ];

What is the difference . PLease help me beacuse $reg is a dynamic value.