i'm creating in my localhost (files will not be published in remote server), a web app where i add some features i need. One of them is upload a wav file, who i want to upload into a different folder for each upload. I used that code that works with normal folder. I edited it in add some options i need (remove blank space in file name etc.), but when i put the "$folderUuid" into the "move_upload_file", the folder is created, but the file isn't uploaded into.
Another feature that i won't be able to understand where to add is to create a uuid folder only when a file is uploaded, not every time the page is refreshed. I read that discussion PHP File Upload Creating Directory and understand that i have to use the $_SESSION, but my code doesn't work.
Here is the php code:
if(isset($_POST['submit']))
{
$allowedExts = array("wav");
$fileName = $_FILES['file']['name'];
$extension = substr($fileName, strrpos($fileName, '.') + 1);
if(!is_dir("inputFiles/". $_SESSION["folder"] ."/")) {
mkdir(uniqid('inputFiles/'), 0700). $_SESSION["folder"] ."/" ;
}
if(in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Name: " . $_FILES["file"]["name"] . "<br />";
echo "File kind: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
if (file_exists("inputFiles/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " file già esistente. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"], $folderUuid . str_replace(" ", "",$_FILES["file"]["name"]));
print "<br />";
echo "Saved in: " . "inputFiles/" . $_FILES["file"]["name"];
print "<br />";
}
}
}
else
{
echo "Invalid file";
}
}
Here is the html code:
<form method="post" enctype="multipart/form-data" >
<label for="file"><span>Filename:</span></label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
Hope someone can help me to fix that problems. Kind Regards Brus