Create destination folder on file upload with same name as f

I’ve been looking at various PHP/AJAX file upload plugins online, but I’m having some trouble finding one feature I really need. For the purposes of this upload, each file that I upload must go into a directory with the same name as that file (minus the extension). Naturally, the nicest way would be to create that folder …

via PHP Website Development » Search Results » ajax:

Create destination folder on file upload with same name as f

I’ve been looking at various PHP/AJAX file upload plugins online, but I’m having some trouble finding one feature I really need. For the purposes of this upload, each file that I upload must go into a directory with the same name as that file (minus the extension). Naturally, the nicest way would be to create that folder during the upload and then send the file to it. I know this involves mkdir() in some way, and I’ve found a number of scripts that even perform basic folder creation, but I’m not clear on how to do this dynamically using the filename. Any ideas?
Thanks!
……………………………………..

When you upload a file in php it is stored in the $_FILES array, its name is stored in $_FILES[‘inputfield’][‘name’] where ‘inputfield’ is the name in the file input like:
So then you would do:
$exp = explode(“.”,$_FILES[‘inputfield’][‘name’]);
$filename = $exp[0];
$path = “/path/to/base/folder/” . $filename . “/” . $_FILES[‘inputfield’][‘name’];
move_uploaded_file($_FILES[‘inputfield’][‘tmp_name’], $path);
……………………………………..

$fileName = $_FILES[‘fieldname’][‘name’]
$foldername = substr($fileName, 0, strrpos($fileName, ‘.’));

For more info: Create destination folder on file upload with same name as f

PHP Website Development » Search Results » ajax

Create destination folder on file upload with same name as f

Share this post:

Related Posts

Leave a Comment