hi php geniuses :)
a simple question for u ppl here's my code and i want to upload all files i.e. images, videos, audios, ppt, pdf etc but here ican only upload the images successfully.. when i upload audio file it gives following error. please check my code and suggest a solution tahnx in advance :)

this is add-material.php

<div class="span-18 last">
    <h2 class="alt">Add Material</h2>
<form id="form" method="post" action="add-material-action.php" enctype="multipart/form-data">
<label for="title">Title:</label><input  type="text" name="title" id="title" class="text "value="" /><br />
<label for="url">Url:</label><input type="text" name="url" id="url" class="text" value="" /><br />
<input type="radio" name="source" value="E" checked />External
<input type="radio" name="source" value="I" />Internal<br /><br />
<label for="description">Course Description:</label><br /><textarea name="description" id="description"></textarea> <br />
<label for="external_id">External Id:</label><input type="text" class="text" name="external_id" value="" /><br /><br />
<label for="file">Upload Your File Here:</label><input type="file" name="uploadedfile" id="uploadedfile"/><br /><br />
<label for="internalfilename">Internal File Name:</label><input type="text" class="text" name="internalfilename" value="" /><br /><br />
<label for="internalfilesize">File Size (for internal files only):</label><input type="text" name="internalfilesize" class="text" value="" /><br /><br />
<label for="externalduration">Duration (Only for externalfiles):</label><input type="text" name="externalduration" class="text" value="" /><br /><br />
<label for="type">Type:</label>
<select name="type" value="<?php echo $type; ?>">
<optgroup label="VIDEO">
<option value="youtube video">youtube video</option>
<option value="vimeo video">vimeo video</option>
<option value="Dailymotion video">Dailymotion video</option>
<optgroup label="AUDIO">
<option value="youtube audio">Youtube Audio</option>
<optgroup label="Images">
<option value="Flickr">Flickr</option>
<option value="Picasa">Picasa</option>
<option value="Slide Share">Slide Share</option>
<optgroup label="PDF">
<option value="Online Documents">Online Documents</option>
<optgroup label="Internal Files">
<option value="image">Image</option>
<option value="audio">Audio</option>
<option value="video">Video</option>
<option value="ppt">Presentation</option>
<br />
<br />
<label>Choose Course:</label>
if (!$con) { die('Could not connect: ' . mysql_error()); }

mysql_select_db($dbname, $con);

$result = mysql_query("SELECT * FROM courses WHERE(accountsid='".$id."')");
echo "<select name='coursesid'>\n";
while($row = mysql_fetch_array($result))
  echo "<option value='".$row['id'] . "'";
  if ($_POST["courseid"]==$row['id']) 
    echo " selected='selected'";
  echo ">" . $row['title'] . "</option>\n";
echo "</select>\n";
<br />
<br />
<select type="text" name="order" value="<?php echo $order; ?>" >
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<br />
<br />
<input class="mybutton" type="submit" name="Add Material" class="button"  value="Add Material" />


and this is my add-material-action.php


$allowedExts = array("jpg", "jpeg", "gif", "png","txt","doc","pdf","mp3","mp4"."ppt");
$extension = end(explode(".", $_FILES["uploadedfile"]["name"]));
if (( ($_FILES["uploadedfile"]["type"] == "image/gif")
|| ($_FILES["uploadedfile"]["type"] == "audio/mpeg")
|| ($_FILES["uploadedfile"]["type"] == "video/mp4")
|| ($_FILES["uploadedfile"]["type"] == "application/msword")
|| ($_FILES["uploadedfile"]["type"] == "application/pdf")
|| ($_FILES["uploadedfile"]["type"] == "application/vnd.ms-powerpoint")
|| ($_FILES["uploadedfile"]["type"] == "text/plain")
|| ($_FILES["uploadedfile"]["type"] == "application/pdf")
|| ($_FILES["uploadedfile"]["type"] == "image/jpeg")
|| ($_FILES["uploadedfile"]["type"] == "image/png")
|| ($_FILES["uploadedfile"]["type"] == "image/pjpeg"))
&& in_array($extension, $allowedExts)) 
 if ($_FILES["uploadedfile"]["error"] > 0)
 echo "Return Code: " . $_FILES["uploadedfile"]["error"] . "<br />";

 elseif (file_exists("graphics/learningmaterial/" . $_FILES["uploadedfile"]["name"]))
  echo $_FILES["uploadedfile"]["name"] . " already exists. ";

$target_path = "graphics/learningmaterial/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
    echo "The file ".  basename( $_FILES['uploadedfile']['name']).
    " has been uploaded";
    echo "There was an error uploading the file, please try again!";



if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db($dbname, $con);
$sql=("INSERT INTO learningmaterial VALUES (NULL,'".$title."', '".$url."','".$source."','".$description."','".$extid."','".$filename."','".$filesize."','".$target_path."','".$duration."','".$courseid."','".$type."','".$order."')");
if (!mysql_query($sql,$con))
  die('Error: ' . mysql_error());
echo header("Location:manage-material.php?status=1&id=".$courseid);


4 Years
Discussion Span
Last Post by Riu 2009
Featured Replies
  • 1
    diafol 3,669   4 Years Ago

    $allowedExts = array("jpg", "jpeg", "gif", "png","txt","doc","pdf","mp3","mp4"."ppt"); should be: $allowedExts = array("jpg", "jpeg", "gif", "png","txt","doc","pdf","mp3","mp4","ppt"); Notice the period/comma confusion before the ppt? Also before checking the nature of $_FILES[...] vars, make sure they exist first. Read More


just forgot to paste the error, sorry about that.. this is the error it gives

Strict Standards: Only variables should be passed by reference in C:\xampp\htdocs\project\teacher\add-material-action.php on line 6
The file abc.mp3 has been uploaded Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near abc.mp3','4 mins','17','audio','2')' at line 1
$allowedExts = array("jpg", "jpeg", "gif", "png","txt","doc","pdf","mp3","mp4"."ppt");

should be:

$allowedExts = array("jpg", "jpeg", "gif", "png","txt","doc","pdf","mp3","mp4","ppt");

Notice the period/comma confusion before the ppt?

Also before checking the nature of $_FILES[...] vars, make sure they exist first.

Edited by diafol


thanx for ur response @diafol
sir, its again saying the same thing...same code is working perfectly for images...but not for audio.. i couldnot get the reason...

how would i check that they exixt???

($_FILES["uploadedfile"]["type"] == "audio/mpeg")

should be

($_FILES["uploadedfile"]["type"] == "audio/mp3")

@diafol i've changed it but the results are same...

i've added some snapshots to clarify

Attachments after_clicking_add_material.JPG 76.01 KB all_fileds_are_empty_in_mysql.JPG 69.58 KB audio_file_upload.JPG 47.29 KB

It seems that your errors stem from $title not existing and subjectid. Have you checked to see that the file is actually uploaded? Just because it doesn't appear in the DB, doesn't mean that the upload didn't work.

The SQL may be easier to deconstruct with the SET syntax as opposed to VALUES.

When you upload an file, do a "strategic echo", e.g.

echo $_FILES['uploadedfile']['type'];

In addition, it may be useful to do a


to see what you get


sir, u r right its uploading the files..i've checked in the folder all the files are there... but its not saving anything database... what should i do then???



its giving error on line 6 i.e
$allowedExts = array("jpg", "jpeg", "gif", "png","txt","doc","pdf","mp3","mp4"."ppt");

and the error is Strict Standards: Only variables should be passed by reference


Are you sure that this is the line that's causing the problem?

In order to get the file extension, use

$extension = pathinfo($filename, PATHINFO_EXTENSION);

And have you changed:

$allowedExts = array("jpg", "jpeg", "gif", "png","txt","doc","pdf","mp3","mp4"."ppt");


$allowedExts = array("jpg", "jpeg", "gif", "png","txt","doc","pdf","mp3","mp4","ppt");

You've posted the same mistake again.

WRT to the error, it's probably due to the end() leading to possible mem leaks. I'd use pathinfo, but if you really MUST use end(), you split the functions:

$bits = explode(".", $_FILES["uploadedfile"]["name"]);
$extension = end($bits);

Edited by diafol


@diafol i just copied the line from my first post.. yeah im sure i've changed everything + i've added more extensions as well...

now i will try the same.. thnk you

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.