i'm a n00b and need some help with a simple upload script.
I have ImpressCMS installed and I'm not satisfied with any of the upload modules i've found. all i want is something simple so members can upload their own mp3s to a directory with their username (created upon first upload).
I have:
/////////////////////////////////////////////////////////////////////////////////////
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" media="all" href="../../../themes/noxiousfix/style.css" />
</head>
<body>
<table><tr><td>
<?php
include("../../../mainfile.php");
include(XOOPS_ROOT_PATH."/header.php");
$dir = "/htdocs/music/user_submitted/"; //Change this to the correct dir RELATIVE TO WHERE THIS SCRIPT IS, or /full/path/
//MIME types to allow, Gif, jpeg, zip ::Edit this to your liking
$types = array("application/pdf","image/png","image/x-png","audio/mpeg","image/gif","image/jpeg","image/pjpeg");
//Check to determine if the submit button has been pressed
if((isset($_POST['submit'])) and ($_POST['PW'] == $pw)){
//Shorten Variables
$tmp_name = $_FILES['upload']['tmp_name'];
$new_name = $_FILES['upload']['name'];
$path = $_POST['subdir'];
$fullpath = "$dir$path/";
$fullpath = str_replace("..", "", str_replace("\.", "", str_replace("//", "/", $fullpath)));
$clean_name = ereg_replace("[^a-z0-9._]", "", str_replace(" ", "_", str_replace("%20", "_", strtolower($new_name) ) ) );
// lets see if we are uploading a file or doing a dir listing
if(isset($_POST['Dir'])){
echo "Directory listing for $fullpath\n";
scandir("$fullpath");
}else{
//Check MIME Type
if ((in_array($_FILES['upload']['type'], $types)) and (!file_exists($fullpath.$clean_name))){
// create a sub-directory if required
if (!is_dir($fullpath)){
mkdir("$fullpath", 0755);
}
//Move file from tmp dir to new location
move_uploaded_file($tmp_name,$fullpath . $clean_name);
echo "$clean_name was uploaded sucessfully";
}else{
//Print Error Message
echo "<small>File <strong><em>{$_FILES['upload']['name']}</em></strong> Was Not Uploaded - bad file type or file already exists</small><br />";
//Debug
$name = $_FILES['upload']['name'];
$type = $_FILES['upload']['type'];
$size = $_FILES['upload']['size'];
$tmp = $_FILES['upload']['name'];
echo "Name: $name<br />Type: $type<br />Size: $size<br />Tmp: $tmp";
}
}
} else {
echo 'Ready to upload your file';
} ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<legend class="header" style="width:98.2%">Upload Files</legend><br>
Please make sure your mp3 ID tags are correct and complete before upload.<br>
File to upload: <br><input type="file" name="upload" /><br><br>
Folder to create/use:<br><input type="text" name="subdir" value="<?php $path = $_POST['subdir']; echo "$path";?>" /> **Must specify<br />
<input type="submit" name="submit" value="Upload File" />
</form>
</td></tr></table>
/////////////////////////////////////////////////////////////////////////////////////
this code allows anyone to choose an upload and create a directory within my upload directory root.
i cant figure out how to make this script recognize the user by name and then create a directory using their uname....
i'm not asking for someone to do this for me, but it would be awesome if some could at least point me in the right direction.
thanks in advance... =)