Go Back   Computer Forums > Web Design | Website Development > Web Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 07-19-2006, 11:45 AM   #11
G9
Daemon Poster
 
G9's Avatar
 
Join Date: Apr 2005
Posts: 1,132
Default Re: Podcast Submission Form

So all I have to change is the email for myself, and at that, only once in the entire script? I guess I'll change the file extensions to .mp3...

I got the email. It also uploaded successfully... in addition, I'd like to know if it's possible that if there is an error uploading (like wrong extension, etc...) if all the inputted information could be retained. For example, I first tried uploading an mp3 when only images were allowed, and all the information I had filled out in the form had been erased.

And since this submission is email-based, I'd email the submitter with acceptance/rejection... so I would change the upload.php to display a reminder to check email regularly, or the upload_class.php?

EDIT: I also noticed that the file is renamed to the artist's name... how can I change this?
__________________

__________________
g9music.com
G9 is offline   Reply With Quote
Old 07-31-2006, 09:10 AM   #12
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,006
Default Re: Podcast Submission Form

Sorry it took so long to get back to you, but I thought it'd be better if i tested it before I said anything again.

it seems that the reason that the files were renamed on upload is that the uploaded script looks for the variable name and calls the file that (not an overly bad feature, but not a great one either)...


anyway...
this script should work now.

Code:
<?php
include ("upload_class.php"); //classes is the map where the class file is stored (one above the root)

$max_size = 1024*250; // the max. size for uploading

$my_upload = new file_upload;

$my_upload->upload_dir = $_SERVER['DOCUMENT_ROOT']."/test/"; // "files" is the folder for the uploaded files (you have to create this folder)
$my_upload->extensions = array(".png", ".zip", ".pdf"); // specify the allowed extensions here
// $my_upload->extensions = "de"; // use this to switch the messages into an other language (translate first!!!)
$my_upload->max_length_filename = 50; // change this value to fit your field length in your database (standard 100)
$my_upload->rename_file = true;

if(isset($_POST['Submit'])) {
    $my_upload->the_temp_file = $_FILES['upload']['tmp_name'];
    $my_upload->the_file = $_FILES['upload']['name'];
    $my_upload->http_error = $_FILES['upload']['error'];
    $my_upload->replace = (isset($_POST['replace'])) ? $_POST['replace'] : "n"; // because only a checked checkboxes is true
    $my_upload->do_filename_check = (isset($_POST['check'])) ? $_POST['check'] : "n"; // use this boolean to check for a valid filename
    $new_name = (isset($_POST['name'])) ? $_POST['name'] : "";
    if ($my_upload->upload($new_name)) { // new name is an additional filename information, use this to rename the uploaded file
        $full_path = $my_upload->upload_dir.$my_upload->file_copy;
        $info = $my_upload->get_uploaded_file_info($full_path);
        // ... or do something like insert the filename to the database
        //since filename is uploaded send an enail to site authour for new submissions
        $aname = $_REQUEST['aname'];
        $email = $_REQUEST['email'];
        $cname = $_REQUEST['cname'];
        $address = $_REQUEST['address'];
        $song = $_REQUEST['sname'];
//make a new name for the file
$name = $aname . "-" . $song;
        $message = "Hello G9,\r\nYou've been sent a podcast submission by $aname. details as follows:\r\n\tName:$name\r\n\tEmail:$email\r\n\tCo  mmunity Name:$cname\r\n\tCommunity Address:$address\r\n\tSong Name:$song\r\n\nThis file has been uploaded to your webspace awaiting your approval.";
        $to      = 'YOUR EMAIL HERE';
        $subject = 'New Podcast Submissions!';
        $headers = "From: $email" . "\r\n" .
   "Reply-To: $email" . "\r\n" .
   "X-Mailer: PHP/" . phpversion();

mail($to, $subject, $message, $headers);
    }
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Upload example</title>
<style type="text/css">
<!--
label {
    float:left;
    display:block;
    width:120px;
}
input {
    float:left;
}
-->
</style>
</head>

<body>
<h3>File upload script:</h3>
<p>Max. filesize = <?php echo $max_size; ?> bytes.</p>
<form name="form1" enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_size; ?>"><br>
  <label for="upload">Select a file...</label><input type="file" name="upload" size="30"><br clear="all">
<label for="name">Artists Name</label><input type="text" name="aname" /><br clear="all">
<label for="email">Email:</label><input type="text" name="email" /><br clear="all">
<label for="cname">Community Name:</label><input type="text" name="cname" /><br clear="all">
<label for="address">Community Address:</label><input type="text" name="address" /><br clear="all">
<label for="sname">Song Name:</label><input type="text" name="sname" /><br clear="all">

  <input style="margin-left:120px;" type="submit" name="Submit" value="Submit">
</form>
<br clear="all">
<p><?php echo $my_upload->show_error_string(); ?></p>
<?php if (isset($info)) echo "<blockquote>".nl2br($info)."</blockquote>"; ?>
</body>
</html>
__________________

__________________
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Old 07-31-2006, 11:54 PM   #13
G9
Daemon Poster
 
G9's Avatar
 
Join Date: Apr 2005
Posts: 1,132
Default Re: Podcast Submission Form

Ironic and most unfortunate that you reach me now... I am currently on leave without access to a computer... I'll be back on the 12th with results. I'm currently typing away on an onscreen keyboard. Thanks for the reply.
__________________
g9music.com
G9 is offline   Reply With Quote
Old 08-01-2006, 01:51 AM   #14
BSOD
 
dodmasta's Avatar
 
Join Date: Jul 2006
Posts: 74
Send a message via Yahoo to dodmasta
Default Re: Podcast Submission Form

If you want me to help test it i can, i do have a webserver.
dodmasta is offline   Reply With Quote
Old 08-01-2006, 08:53 PM   #15
G9
Daemon Poster
 
G9's Avatar
 
Join Date: Apr 2005
Posts: 1,132
Default Re: Podcast Submission Form

Quote:
Originally Posted by dodmasta
If you want me to help test it i can, i do have a webserver.
Thanks for the offer, but my disorganized state would only become more confusing.
__________________
g9music.com
G9 is offline   Reply With Quote
Old 08-10-2006, 05:03 PM   #16
G9
Daemon Poster
 
G9's Avatar
 
Join Date: Apr 2005
Posts: 1,132
Default Re: Podcast Submission Form

Well, it works... but it still gets renamed to a weird combination of numbers.
__________________
g9music.com
G9 is offline   Reply With Quote
Old 08-11-2006, 10:05 AM   #17
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,006
Default Re: Podcast Submission Form

grrr.... dammit, (I guess that's what I get for trying to take a shortcut and using an existing script!!

I'll make a new upload script and then it should all work fine.
__________________
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Old 08-11-2006, 10:57 AM   #18
G9
Daemon Poster
 
G9's Avatar
 
Join Date: Apr 2005
Posts: 1,132
Default Re: Podcast Submission Form

Alright thanks man... you don't know how much I appreciate your effort.
__________________
g9music.com
G9 is offline   Reply With Quote
Old 09-15-2006, 06:19 AM   #19
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,006
Default Re: Podcast Submission Form

ok...

as with the above message forget everything previous to that message... ghere a new (self contained script)... that works better.

it has a max file upload size of 5 megs.
but you can change that.
and it checks what files are uploaded by checking the mime type rather than the extension, (so people can't just rename files with a different extentsion.
it currently accepts all music file types, but you can edit where necessary.

the things you may like to change are...
the accepted mime type.
the $mypath varable to say wher eyou want the files to be uploaded
the email address variable.
and the content of the form.

other than that I poperly tested the form this time so I know it works without any weird or wonderful things that I'm not sure about.


Code:
<?php
$artist = @$_REQUEST['artist'];
$genre = @$_REQUEST['genre'];

if (@$HTTP_POST_VARS['submit'])
{
    if ($genre=="")
    {
        $error = "You Must Specify A Genre";
    }
    else
    {
        if ($artist=="")
        {
            $error = "You must specify your Artist Name";
        }
        else
        {
            //print_r($HTTP_POST_FILES);
            if (!is_uploaded_file($HTTP_POST_FILES['file']['tmp_name']))
            {
                $error = "You did not upload a file!";
                unlink($HTTP_POST_FILES['file']['tmp_name']);
                // assign error message, remove uploaded file, redisplay form.
            }
            else
            {
                //a file was uploaded
                $maxfilesize=5242880;//5MB
                if ($HTTP_POST_FILES['file']['size'] > $maxfilesize)
                {
                    $error = "file is too large";
                    unlink($HTTP_POST_FILES['file']['tmp_name']);
                    // assign error message, remove uploaded file, redisplay form.
                }
                else
                {
                    if (
                    ($HTTP_POST_FILES['file']['type'] != "application/zip") /*zip files*/
                    AND($HTTP_POST_FILES['file']['type'] != "audio/x-mpegurl") /*mp3*/
                    AND($HTTP_POST_FILES['file']['type'] != "audio/mpeg3") /*mp3*/
                    AND($HTTP_POST_FILES['file']['type'] != "audio/x-mpeg-3") /*mp3*/
                    AND($HTTP_POST_FILES['file']['type'] != "audio/x-mpeg") /*mp3*/
                    AND($HTTP_POST_FILES['file']['type'] != "audio/mpeg") /*mp2 sound*/
                    AND($HTTP_POST_FILES['file']['type'] != "audio/x-wav") /*wave files*/
                    AND($HTTP_POST_FILES['file']['type'] != "audio/x-aiff") /*aif aiff aifc*/
                    AND($HTTP_POST_FILES['file']['type'] != "audio/midi") /*mid*/
                    AND($HTTP_POST_FILES['file']['type'] != "audio/x-midi") /*mid*/
                    AND($HTTP_POST_FILES['file']['type'] != "audio/basic") /*au snd*/
                    AND($HTTP_POST_FILES['file']['type'] != "audio/x-pn-realaudio") /*real media*/
                    )
                    {
                        $error = "This file type is not allowed";
                        unlink($HTTP_POST_FILES['file']['tmp_name']);
                    // assign error message, remove uploaded file, redisplay form.
                    }
                    else
                    {
                        //File has passed all validation, copy it to the final destination and remove the temporary file:
                        //create file structure for cataloging files
                        $mypath="C:\\program files\\apache group\\apache2\\httpdocs\\upload\\$genre\\$artist";
                        @mkdir($mypath,0777,TRUE);
                        copy($HTTP_POST_FILES['file']['tmp_name'],"$mypath\\".$HTTP_POST_FILES['file']['name']);
                        unlink($HTTP_POST_FILES['file']['tmp_name']);
                        print "File has been successfully uploaded!";
                        
                        $email = "your address here";
                        $subject = "You have new Podcast material";
                        $message = "Hello G9 you've recieve a new subbmission for your podcasting, from $artist, the new song is $HTTP_POST_FILES['file']['name']";
                        mail($to, $subject, $message);
                        exit;
                    }
                }
            }
        }
    }
}
?>

<html>
<head></head>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
<?=@$error?>
<br><br>
Artist:<input type="text" name="artist" value="<?=@$artist?>" /><br />
Genre: <input type="text" name="genre" value="<?=@$genre?>" /><br />

Choose a file to upload:<br>
<input type="file" name="file"><br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
__________________
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Old 09-15-2006, 06:22 PM   #20
G9
Daemon Poster
 
G9's Avatar
 
Join Date: Apr 2005
Posts: 1,132
Default Re: Podcast Submission Form

So... save this as html or php?

Thanks for helping out, again... I appreciate it. Something got screwed up with the PM system... got a PM notification in my email but didn't find anything in my inbox.
__________________

__________________
g9music.com
G9 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 08:58 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0