Jump to content

need much help with upload script


noxiousfix

Recommended Posts

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... =)

Link to comment
Share on other sites

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> 
}
?>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.