I have a file upload script that works just fine, however, I also need to extract the filename from the upload script, so I can store the name in a database for usage later on. After the upload form, and before processing, I also append a variable name to the front of the file, to name the file with the associated project. As I said, the script works just as it should, the files are uploaded and renamed correctly. Her is the form:
$project=$_SESSION['project'];
echo '<span class="route"><h3><a href="index.php?select=mstudio" target ="_self">Studios</a> ';
echo ' - <a href="index.php?studio=' . $studio . '" target ="_self">' . $studio . ' </a> - ' . $project . '</h3></span>';
// echo 'Add a new track to the project ' . $project;
echo '<form enctype="multipart/form-data" action="index.php" method="POST">';
echo '<input type="hidden" name="trackupload" value="yes">';
echo '<input type="hidden" name="MAX_FILE_SIZE" value="10000000">';
echo '<table>';
echo '<tr>';
echo '<td>Please select a track to UpLoad</td>';
echo '</tr>';
echo '<tr>';
echo '<td><input name="uploaded" type="file" size ="60"/></td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="submit" value="Add Track!"><input type="reset"></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
Here is the processing portion:
$project=$_SESSION['project'];
$track=basename( $_FILES['uploadedfile']['name']);
// Where the file is going to be placed
$target = "studios/";
$target = $target . $project . '_' . basename( $_FILES['uploaded']['name']) ;
if (file_exists($target))
{
echo ' DUPLICATE FILE!!!!';
}
$ok=1;
// $track=basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else
{
echo mysql_error();
}
$pname=$_SESSION['project'];
$uname=$_SESSION['user'];
$tdate=date("y-m-d H:i:s", time());
echo $pname, $uname, $track, $tdate;
The last echo statement is so I can see if it is working, the $track is the variable that is supposed to reflect the uploaded file name. Why is it not working? I must be not extracting the filename correctly to assign it to a variable, however, the file is uploaded correctly.
Ice