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-10-2006, 05:01 PM   #1
G9
Daemon Poster
 
G9's Avatar
 
Join Date: Apr 2005
Posts: 1,132
Default Podcast Submission Form

Well, I want a nicely styled form that has the following:

1. Artist Name
2. Email
3. Community Name
4. Community Address
5. Song Name
6. File

There are two upload systems I have in mind:
1. Control Panel (please make a special viewing page in this case, for example if it is submitted then in the account-driven"control panel" all the submitted information appears in a table [so the rows would be numbered, and the columns would be artist name, email, community name, community address, song name, file download link, date/time submitted, reject <automatically sends email to artist with rejection notice, as well as deleting the song file and removing it from the list>, accept <automatically sends email to artist with acceptance notice>, and delete <deletes song file and removes it from the list without sending any notice... this is for accepted songs that are from previous podcasts and no longer need to be viewed>].
2. Email (Sends all information and file [as attachment] to an email address)

I'd prefer the first file upload option, if it isn't too difficult.

As of now, I have nothing but gratitude and advertisement space to provide. But I'm sure that more than compensates.
__________________

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

I'm going to split this into multiple posts.

I'll have a go at number two first, (since that's the easiest).

firstly you'll need a suibmission form.

('ill let you do the styling, I'll just give you a blank form).
Code:
<html>
<body>
<form action=podmail.php method=post><br />
Name:<input type="text" name="name" /><br />
Email:<input type="text" name="email" /><br />
Community Name:<input type="text" name="cname" /><br />
Community Address:<input type="text" name="address" /><br />
Song Name:<input type="text" name="sname" /><br />
Song:<input type="file" name="mp3" /><br />
<input type="Submit" value="upload!" /><br />
</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 07-11-2006, 08:25 AM   #3
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,004
Default Re: Podcast Submission Form

I've just thought of something, (that is essential in both cases). do php based file upload forms work on your server, I was writting a script for this and testing it on the server here at work, but the way it is set up means that most of the paths are actually only virtual directories, (I.e where the usernames and such are), and that breaks the file upload script that I wrote,

before a file can be emailed to you it first has to be uploaded.
__________________
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-11-2006, 02:18 PM   #4
G9
Daemon Poster
 
G9's Avatar
 
Join Date: Apr 2005
Posts: 1,132
Default Re: Podcast Submission Form

Quote:
Originally Posted by root
I've just thought of something, (that is essential in both cases). do php based file upload forms work on your server, I was writting a script for this and testing it on the server here at work, but the way it is set up means that most of the paths are actually only virtual directories, (I.e where the usernames and such are), and that breaks the file upload script that I wrote,

before a file can be emailed to you it first has to be uploaded.
I see... well I can't be sure of that, my current rig won't boot up Windows, so I'm currently using my Palm TX to post this... how would I test server compatibility?
__________________
g9music.com
G9 is offline   Reply With Quote
Old 07-12-2006, 12:00 PM   #5
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,004
Default Re: Podcast Submission Form

um... to see if you are able to have files uploaed to your server you should put this script on it and try and see if you can upload something.

(I just coppied this script from www.phpclasses.net)

first this file, (call it upload_class.php)
Code:
<?php 
/*
Easy PHP Upload - version 2.29
A easy to use class for your (multiple) file uploads

Copyright (c) 2004 - 2006, Olaf Lederer
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    * Neither the name of the finalwebsites.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

______________________________________________________________________
available at http://www.finalwebsites.com 
Comments & suggestions: http://www.finalwebsites.com/contact.php
*/
class file_upload {
    var $the_file;
	var $the_temp_file;
    var $upload_dir;
	var $replace;
	var $do_filename_check;
	var $max_length_filename = 100;
    var $extensions;
	var $ext_string;
	var $language;
	var $http_error;
	var $rename_file; // if this var is true the file copy get a new name
	var $file_copy; // the new name
	var $message = array();
	var $create_directory = true;
	function file_upload() {
		$this->language = "en"; // choice of en, nl, es
		$this->rename_file = false;
		$this->ext_string = "";
	}
	function show_error_string() {
		$msg_string = "";
		foreach ($this->message as $value) {
			$msg_string .= $value."<br>\n";
		}
		return $msg_string;
	}
	function set_file_name($new_name = "") { // this "conversion" is used for unique/new filenames 
		if ($this->rename_file) {
			if ($this->the_file == "") return;
			$name = ($new_name == "") ? strtotime("now") : $new_name;
			$name = $name.$this->get_extension($this->the_file);
		} else {
			$name = $this->the_file;
		}
		return $name;
	}
	function upload($to_name = "") {
		$new_name = $this->set_file_name($to_name);
		if ($this->check_file_name($new_name)) {
			if ($this->validateExtension()) {
				if (is_uploaded_file($this->the_temp_file)) {
					$this->file_copy = $new_name;
					if ($this->move_upload($this->the_temp_file, $this->file_copy)) {
						$this->message[] = $this->error_text($this->http_error);
						if ($this->rename_file) $this->message[] = $this->error_text(16);
						return true;
					}
				} else {
					$this->message[] = $this->error_text($this->http_error);
					return false;
				}
			} else {
				$this->show_extensions();
				$this->message[] = $this->error_text(11);
				return false;
			}
		} else {
			return false;
		}
	}
	function check_file_name($the_name) {
		if ($the_name != "") {
			if (strlen($the_name) > $this->max_length_filename) {
				$this->message[] = $this->error_text(13);
				return false;
			} else {
				if ($this->do_filename_check == "y") {
					if (preg_match("/^[a-z0-9_]*\.(.){1,5}$/i", $the_name)) {
						return true;
					} else {
						$this->message[] = $this->error_text(12);
						return false;
					}
				} else {
					return true;
				}
			}
		} else {
			$this->message[] = $this->error_text(10);
			return false;
		}
	}
	function get_extension($from_file) {
		$ext = strtolower(strrchr($from_file,"."));
		return $ext;
	}
	function validateExtension() {
		$extension = $this->get_extension($this->the_file);
		$ext_array = $this->extensions;
		if (in_array($extension, $ext_array)) { 
			// check mime type hier too against allowed/restricted mime types (boolean check mimetype)
			return true;
		} else {
			return false;
		}
	}
	// this method is only used for detailed error reporting
	function show_extensions() {
		$this->ext_string = implode(" ", $this->extensions);
	}
	function move_upload($tmp_file, $new_file) {
		umask(0);
		if ($this->existing_file($new_file)) {
			$newfile = $this->upload_dir.$new_file;
			if ($this->check_dir($this->upload_dir)) {
				if (move_uploaded_file($tmp_file, $newfile)) {
					if ($this->replace == "y") {
						//system("chmod 0777 $newfile"); // maybe you need to use the system command in some cases...
						chmod($newfile , 0777);
					} else {
						// system("chmod 0755 $newfile");
						chmod($newfile , 0755);
					}
					return true;
				} else {
					return false;
				}
			} else {
				$this->message[] = $this->error_text(14);
				return false;
			}
		} else {
			$this->message[] = $this->error_text(15);
			return false;
		}
	}
	function check_dir($directory) {
		if (!is_dir($directory)) {
			if ($this->create_directory) {
				umask(0);
				mkdir($directory, 0777);
				return true;
			} else {
				return false;
			}
		} else {
			return true;
		}
	}
	function existing_file($file_name) {
		if ($this->replace == "y") {
			return true;
		} else {
			if (file_exists($this->upload_dir.$file_name)) {
				return false;
			} else {
				return true;
			}
		}
	}
	function get_uploaded_file_info($name) {
		$str = "File name: ".basename($name)."\n";
		$str .= "File size: ".filesize($name)." bytes\n";
		if (function_exists("mime_content_type")) {
			$str .= "Mime type: ".mime_content_type($name)."\n";
		}
		if ($img_dim = getimagesize($name)) {
			$str .= "Image dimensions: x = ".$img_dim[0]."px, y = ".$img_dim[1]."px\n";
		}
		return $str;
	}
	// this method was first located inside the foto_upload extension
	function del_temp_file($file) {
		$delete = @unlink($file); 
		clearstatcache();
		if (@file_exists($file)) { 
			$filesys = eregi_replace("/","\\",$file); 
			$delete = @system("del $filesys");
			clearstatcache();
			if (@file_exists($file)) { 
				$delete = @chmod ($file, 0775); 
				$delete = @unlink($file); 
				$delete = @system("del $filesys");
			}
		}
	}
	// some error (HTTP)reporting, change the messages or remove options if you like.
	function error_text($err_num) {
			// start http errors
			$error[0] = "File: <b>".$this->the_file."</b> successfully uploaded!";
			$error[1] = "The uploaded file exceeds the max. upload filesize directive in the server configuration.";
			$error[2] = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form.";
			$error[3] = "The uploaded file was only partially uploaded";
			$error[4] = "No file was uploaded";
			// end  http errors
			$error[10] = "Please select a file for upload.";
			$error[11] = "Only files with the following extensions are allowed: <b>".$this->ext_string."</b>";
			$error[12] = "Sorry, the filename contains invalid characters. Use only alphanumerical chars and separate parts of the name (if needed) with an underscore. <br>A valid filename ends with one dot followed by the extension.";
			$error[13] = "The filename exceeds the maximum length of ".$this->max_length_filename." characters.";
			$error[14] = "Sorry, the upload directory doesn't exist!";
			$error[15] = "Uploading <b>".$this->the_file."...Error!</b> Sorry, a file with this name already exitst.";
			$error[16] = "The uploaded file is renamed to <b>".$this->file_copy."</b>.";
			

		return $error[$err_num];
	}
}
?>
__________________
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-12-2006, 12:01 PM   #6
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,004
Default Re: Podcast Submission Form

then this file, (call it upload.php)
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']."/files/new/"; // "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 
    } 
} 
?> 
<!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">New name?</label><input type="text" name="name" size="20"> 
  (without extension!) <br clear="all"> 
  <label for="replace">Replace ?</label><input type="checkbox" name="replace" value="y"><br clear="all"> 
  <label for="check">Validate filename ?</label><input name="check" type="checkbox" value="y" checked><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>
then browse to the upload file and try uploading a file...

if that works, I think it might be better to just forget about the email and just concerntrait on the upload idea.
__________________
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-12-2006, 03:19 PM   #7
G9
Daemon Poster
 
G9's Avatar
 
Join Date: Apr 2005
Posts: 1,132
Default Re: Podcast Submission Form

Alright, it uploaded. I don't know where it uploaded to, but it displayed a successful upload message.
__________________
g9music.com
G9 is offline   Reply With Quote
Old 07-17-2006, 05:00 AM   #8
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,004
Default Re: Podcast Submission Form

Quote:
$my_upload->upload_dir = $_SERVER['DOCUMENT_ROOT']."/files/new/"; // "files" is the folder for the uploaded files (you have to create this folder)
Did you create this folder in your document root as a place for the files to go?

this part
Code:
$my_upload->upload_dir = $_SERVER['DOCUMENT_ROOT']."/files/new/";
could be replaced by aything you want

eg.
$my_upload->upload_dir = "/var/www/upload/";
or
$my_upload->upload_dir = "c:\website\upload\"; etc.
__________________
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-17-2006, 11:28 AM   #9
G9
Daemon Poster
 
G9's Avatar
 
Join Date: Apr 2005
Posts: 1,132
Default Re: Podcast Submission Form

Well it worked, but automatically renamed the file.
__________________
g9music.com
G9 is offline   Reply With Quote
Old 07-19-2006, 05:24 AM   #10
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,004
Default Re: Podcast Submission Form

OK...
in the form above change upload.php to be this.

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']."/files/new/"; // "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
        $name = $_REQUEST['name'];
        $email = $_REQUEST['email'];
        $cname = $_REQUEST['cname'];
        $address = $_REQUEST['address'];
        $sname = $_REQUEST['sname'];
        $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\tCommunity 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 ADDRESS 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="name" /><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>
now whenever someone uploads a file it'll email you to tell you their details and let you know that there is a file waiting on your site.
__________________

__________________
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
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 10:24 AM.


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