I’ve followed the tut in how to upload a file. However, im getting an error message and can’t figure out why. Any help would be appreciated.
Error:
[CODE]Fatal error: Call to undefined function: error() in /homepages/31/d221003102/htdocs/dsc046768903/freelance/mutuba/testing/admin/editmp3.php on line 92
Points to the line:
[code=php]@move_uploaded_file($_FILES[$fieldname][‘tmp_name’], $uploadFilename)
or error(‘receiving directory insuffiecient permission’, $uploadForm);
Code:
[code=php]// filename: upload.processor.php
// first let’s set some variables
// make a note of the current working directory, relative to root.
$directory_self = str_replace(basename($_SERVER[‘PHP_SELF’]), ”, $_SERVER[‘PHP_SELF’]);
// make a note of the directory that will recieve the uploaded file
$uploadsDirectory = $_SERVER[‘DOCUMENT_ROOT’] . ‘media/mp3player/music/’;
// make a note of the location of the upload form in case we need it
$uploadForm = ‘editmp3.php’;
// fieldname used within the file <input> of the HTML form
$fieldname = ‘file’;
// Now let’s deal with the upload
// possible PHP upload errors
$errors = array(1 => ‘php.ini max file size exceeded’,
2 => ‘html form max file size exceeded’,
3 => ‘file upload was only partial’,
4 => ‘no file was attached’);
if($_POST[‘submitadd’])
{
// check for PHP’s built-in uploading errors
($_FILES[$fieldname][‘error’] == 0)
or error($errors[$_FILES[$fieldname][‘error’]], $uploadForm);
// check that the file we are working on really was the subject of an HTTP upload
@is_uploaded_file($_FILES[$fieldname][‘tmp_name’])
or error(‘not an HTTP upload’, $uploadForm);
// make a unique filename for the uploaded file and check it is not already
// taken… if it is already taken keep trying until we find a vacant one
// sample filename: 1140732936-filename.jpg
$now = time();
while(file_exists($uploadFilename = $uploadsDirectory.$now.’-‘.$_FILES[$fieldname][‘name’]))
{
$now++;
}
// now let’s move the file to its final location and allocate the new filename to it
@move_uploaded_file($_FILES[$fieldname][‘tmp_name’], $uploadFilename)
or error(‘receiving directory insuffiecient permission’, $uploadForm);
$sql = “INSERT INTO `music` ( `id` , `title` , `composer` , `venue`, `file`, `active`)
VALUES (”,'” . $_POST[‘title’] . “‘, ‘” . $_POST[‘composer’] . “‘, ‘” . $_POST[‘venue’] . “‘, ‘” . $uploadFilename . “‘, ‘” . $_POST[‘active’] . “‘)”;
mysql_query($sql);
header(“Location: editmp3.php?msg=1”);
// The following function is an error handler which is used
// to output an HTML error page if the file upload fails
function error($error, $location, $seconds = 5)
{
header(“Refresh: $seconds; URL=”$location””);
echo ‘<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN”‘.”n”.
‘”http://www.w3.org/TR/html4/strict.dtd”>’.”nn”.
‘<html lang=”en”>’.”n”.
‘ <head>’.”n”.
‘ <meta http-equiv=”content-type” content=”text/html; charset=iso-8859-1″>’.”nn”.
‘ <link rel=”stylesheet” type=”text/css” href=”stylesheet.css”>’.”nn”.
‘ <title>Upload error</title>’.”nn”.
‘ </head>’.”nn”.
‘ <body>’.”nn”.
‘ <div id=”Upload”>’.”nn”.
‘ <h1>Upload failure</h1>’.”nn”.
‘ <p>An error has occured: ‘.”nn”.
‘ <span class=”red”>’ . $error . ‘…</span>’.”nn”.
‘ The upload form is reloading</p>’.”nn”.
‘ </div>’.”nn”.
‘</html>’;
exit;
} // end error handler
}else
{
require(“backendheader.php”);
?>
<div id=”leftnav”>
<?php
require(“leftnav.php”);
?>
</div>
<!– End of leftnav id –>
<div id=”main”>
<?php
if($validentry!=0){
$fillsql = “SELECT * FROM music WHERE id = ” . $validentry . “;”;
$fillres = mysql_query($fillsql);
$fillrow = mysql_fetch_assoc($fillres);
echo “<h1>Edit Song</h1>”;
echo “<p>click<a href=’editmp3.php’> here </a> to add a new song</p>”;
}
else{
echo “<h1>Add New Song</h1>”;
}
//**********************************
//Check if a confirmation message needs to be printed
//**********************************
if($_GET[‘msg’] == 1){
echo “<h5 class=’confirm’>Song Succesfully Added</h5>”;
}
if($_GET[‘msg’] == 2){
echo “<h5 class=’confirm’>Song Succesfully Edited</h5>”;
}
if($_GET[‘msg’] == 3){
echo “<h5 class=’confirm’>Song Succesfully Deleted</h5>”;
}
?>
<form action=”<?php echo $SCRIPT_NAME ?>” enctype=”multipart/form-data” method=”post”>
<table>
<input type=”hidden” name=”id” value=”<?php echo $validentry;?>” />
<tr>
<td>Title:
</td>
<td>
<input type=”text” name=”title” size=”50″ value=”<?= trim($fillrow[‘title’]); ?>”>
</td>
</tr>
<tr>
<td>Composer:
</td>
<td>
<input type=”text” name=”composer” size=”50″ value=”<?= trim($fillrow[‘composer’]); ?>”>
</td>
</tr>
<tr>
<td>Venue:</td>
<td>
<input type=”text” name=”venue” size=”50″ value=”<?= trim($fillrow[‘venue’]); ?>”>
</td>
</tr>
<tr>
<td>File:</td>
<td>
<input type=”file” name=”file”>
<input type=”hidden” name=”MAX_FILE_SIZE” value=”25000″ />
</td>
</tr>
<tr>
<td>Active:</td>
<td>
<select name=”active”>
<option value=”yes”>yes</option>
<option value=”no”>no</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td>
<?php
if($validentry!=0){
echo “<input type=’submit’ name=’submitedit’ value=’Edit Song’ />”;
}
else{
echo “<input type=’submit’ name=’submitadd’ value=’Add Song’ />”;
}
?>
</td>
</tr>
</table>
</form>