noxiousfix Posted February 15, 2009 Share Posted February 15, 2009 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... =) Quote Link to comment Share on other sites More sharing options...
plodos Posted February 15, 2009 Share Posted February 15, 2009 store.php sample <?php function gen_trivial($len = 6) { $r = ''; for($i=0; $i<$len; $i++) $r .= chr(rand(0, 25) + ord('a')); return $r; } $basename = gen_trivial(); $mypath="sw/$basename"; // for ex: www.sss.com/sw/etgwsg/ mkdir($mypath,0777,TRUE); $q = "insert into TABLE_NAME set path='{$basename}', ext='$file_ext', user='{$_SESSION['id']}' "; $result = mysql_query($q); $fid = mysql_insert_id(); move_uploaded_file($_FILES['paper']['tmp_name'], 'sw/'.$basename.'/'.$fid.$file_ext); ?> get.php sample <?php $q = "select * from TABLE_NAME where TABLE_NAME.user={$_SESSION['id']} ORDER BY id ASC"; $result = mysql_query($q); while($row=mysql_fetch_array($result)){ <a href='sw/{$row['path']}/{$row['id']}{$row['ext']}'>{$row['title']}</a> } ?> Quote Link to comment Share on other sites More sharing options...
noxiousfix Posted February 15, 2009 Author Share Posted February 15, 2009 uh... i appreciate the help but it was over my head. i didn't want to add anything to database, just query and add $user_uname to the directory path the make a folder in the users name... sorry, but you def. lost me on that one! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.