Creating directory/folder based on name of file uploaded
Hi,
Hoping someone might be able to help. I don't know if this is the best way to accomplish what I want or not.
I want to be able to create a directory/folder and upload files to that folder based on the first part of the image's filename.
Ex. The file name might be... 2012-southwick-national_smith_0146.jpg
I want to have a directory/folder created as /2012-southwick-national/
To do this I need to strip the "_smith_0146.jpg" from the filename. Any help with the regular expression for "dirString" to do this. I only have it stripping the .jpg
Here is what I have for the coding so far...
<?php
$photoName=((isset($_FILES["photo1"]))? preg_replace('/.[^.]*$/', '', $_FILES["photo1"]["name"]) :"");
?>
<?php
$dirString = '';
$dirString = preg_replace('/.jpg/', '', '$photoName', -1, $dirString);
?>
<?php
// WA_UploadResult1 Params Start
$WA_UploadResult1_Params = array();
// WA_UploadResult1_1 Start
$WA_UploadResult1_Params["WA_UploadResult1_1"] = array(
'UploadFolder' => "../$dirstring/",
'FileName' => "[FileName]",
'DefaultFileName' => "",
'ResizeType' => "0",
'ResizeWidth' => "0",
'ResizeHeight' => "0",
'ResizeFillColor' => "" );
// WA_UploadResult1_1 End
// WA_UploadResult1 Params End
?>