lighthugger Posted March 27, 2008 Share Posted March 27, 2008 Im trying to put together code that will aloow visitors to upload audio to a website. While the audio is stored in a file the information should be passed to a SQL database. I seem to having problems with this though... This is what iv put together so far, unfortunatly it doesnt quite work. Any ideas? <!-- HTML --> <form enctype="multipart/form-data" action="masterupload.php"> <?php $Mix_Namei = getenv("Mix_Name"); $DJi = getenv ("DJ"); $Additional_notesi = getenv ("Additional_Notes"); ?> <input type="hidden" name="Mix Name" value="<?php echo $Mix_Namei ?>" /> <input type="hidden" name="DJ Name" value="<?php echo $DJi ?>" /> <input type="hidden" name="Mix Discription" value="<?php echo $Additional_Notesi ?>" /> DJ Name <br /> <input type="text" name="DJ Name" size="35" /> <br /> Mix Name<br /> <input type="text" name="Mix Name" size="35" /> <br /> <br /> Mix Discription <br /> <textarea name="Mix Discription" rows="4" cols="40"></textarea> <br /> <br /><input type="hidden" name="MAX_FILE_SIZE" value="100000000" /> Choose a file to upload:<br /> <input name="uploadedfile" type="file" /> <br /> <br /> <input type="submit" value="submit" /> <br /> </form> <!-- check.php --> <?php $host= ""; $dbuser= ""; $dbpass= ""; $database= ""; $table= "mp3_files"; $link= @mysql_connect($host, $dbuser, $dbpass) or die ('I cannot connect to the database because: ' . mysql_error()); if (! @mysql_select_db($database,$link)){ mysql_query("CREATE DATABASE $database"); } else { if(! @mysql_query("SELECT * FROM `$table` LIMIT 0,1")){ $sql="CREATE TABLE $table ( id INT NOT NULL auto_increment , Mix_Name VARCHAR(255) NOT NULL , DJ VARCHAR(255) NOT NULL , Additional_Notes VARCHAR(50) NOT NULL , Path VARCHAR(255) NOT NULL , PRIMARY KEY (id) )" ; mysql_query($sql); } } ?> <!-- masterupload.php --> <?PHP if ($_POST['action']) { $dir = "http://www."; $uploadfile = $dir . $_FILES['mp3_file']['name']; move_uploaded_file($_FILES['mp3_file']['tmp_name'], $uploadfile); include 'check.php'; $sql = "INSERT INTO $table (Mix_Name, DJ, Additional_Notes, Path ) VALUES ($_POST[name], $_POST[DJ], $_POST[notes],$uploadfile)"; mysql_query($sql); } ?> Link to comment https://forums.phpfreaks.com/topic/98184-audio-upload-feature/ Share on other sites More sharing options...
BlueSkyIS Posted March 27, 2008 Share Posted March 27, 2008 can you expand on "it doesnt quite work"? Link to comment https://forums.phpfreaks.com/topic/98184-audio-upload-feature/#findComment-502339 Share on other sites More sharing options...
lighthugger Posted March 27, 2008 Author Share Posted March 27, 2008 I certainly can, I cant get it working at all, the form allows users to iput there information and browse for the file they wish to upload, but on confirm it all goes wrong. The information isnt being transfered to my database. Link to comment https://forums.phpfreaks.com/topic/98184-audio-upload-feature/#findComment-502445 Share on other sites More sharing options...
BlueSkyIS Posted March 27, 2008 Share Posted March 27, 2008 couple problems here: if ($_POST['action']) { // Issue 1 $dir = "http://www."; // Issue 2 $uploadfile = $dir . $_FILES['mp3_file']['name']; move_uploaded_file($_FILES['mp3_file']['tmp_name'], $uploadfile); Issue 1: There is no form field with the NAME='action', so $_POST['action'] will always be false. My preference is to use this instead: if ($_SERVER['REQUEST_METHOD'] == "POST") { Issue 2: The path to your upload directory must be an absolute path, not a URL. This is an example of an absolute path: /home/web/public_html/uploads/ Link to comment https://forums.phpfreaks.com/topic/98184-audio-upload-feature/#findComment-502462 Share on other sites More sharing options...
lighthugger Posted April 7, 2008 Author Share Posted April 7, 2008 I v made some changes, heres my code at the mo. When i hit submit the url changes to incorporate the information but nothing actually happens. Dam this is a tricky one... masterupload.php <?PHP if ($_SERVER['REQUEST_METHOD'] == "POST") { $dir = "/mp3_files/"; $uploadfile = $dir . $_FILES['mp3_file']['name']; move_uploaded_file($_FILES['mp3_file']['tmp_name'], $uploadfile); include 'check.php'; $sql = "INSERT INTO $table (Mix_Name, DJ, Additional_Notes, Path ) VALUES ($_POST[name], $_POST[DJ], $_POST[notes],$uploadfile)"; mysql_query($sql); } ?> check.php <?php $host= ""; $dbuser= ""; $dbpass= ""; $database= ""; $table= "mp3_files"; $link= @mysql_connect($host, $dbuser, $dbpass) or die ('I cannot connect to the database because: ' . mysql_error()); if (! @mysql_select_db($database,$link)){ mysql_query("CREATE DATABASE $database"); } else { if(! @mysql_query("SELECT * FROM `$table` LIMIT 0,1")){ $sql="CREATE TABLE $table ( id INT NOT NULL auto_increment , Mix_Name VARCHAR(255) NOT NULL , DJ VARCHAR(255) NOT NULL , Additional_Notes VARCHAR(50) NOT NULL , Path VARCHAR(255) NOT NULL , PRIMARY KEY (id) )" ; mysql_query($sql); } } ?> html upload page code <form enctype="multipart/form-data" action="masterupload.php"> DJ Name <input type="text" name="DJ Name" size="35" /> <br /> Mix Name <input type="text" name="Mix Name" size="35" /> <br /> Mix Discription <textarea name="Mix Discription" rows="4" cols="40"></textarea> <br /> Choose a file to upload: <input name="uploadedfile" type="file" /> <br /> <input type="submit" value="submit" /> </form> Link to comment https://forums.phpfreaks.com/topic/98184-audio-upload-feature/#findComment-511222 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.