Matt555
iMod
I'm trying to get a file upload system on my site to allow users to upload smileys/graphics to be displayed on the site (and then possibly give them a link to the uploaded file), I've tried a couple of tutorials on the net but to no avail...
The code I'm using at the minute for the upload.php file is attached.
I'm getting this error
File: Size:
Fatal error: Call to undefined function: verify_uploaded_file() in /home/matt555/public_html/upload.php on line 44
Does anyone know what I can do to get it working?
www.matt-brunt.com/upload.htm is the upload page used. At the minute it's only set to allow jpg and jpeg file types to be uploaded but gif's and png's are going to be added soon.
Thanks in advance - Matt
The code used is from a tutorial as I don't really know the first thing about php. :O
The code I'm using at the minute for the upload.php file is attached.
I'm getting this error
File: Size:
Fatal error: Call to undefined function: verify_uploaded_file() in /home/matt555/public_html/upload.php on line 44
Does anyone know what I can do to get it working?
www.matt-brunt.com/upload.htm is the upload page used. At the minute it's only set to allow jpg and jpeg file types to be uploaded but gif's and png's are going to be added soon.
Thanks in advance - Matt
The code used is from a tutorial as I don't really know the first thing about php. :O
PHP:
<?php
// Upload.php – file upload script
// The $MOVE_TO_PATH is the COMPLETE path to the directory
// of where the file should go. (include trailing slash.)
$MOVE_TO_PATH =
'/home/matt555/public_html/images/userupload/';
// The following values are used to verify_uploaded_file()
// as the sizes and types that can be uploaded.
$UPLOAD_TYPES['.jpg'] = 1; // Allow .jpg files
$UPLOAD_TYPES['.jpeg'] = 2; // Allow .jpeg files
$UPLOAD_SIZES['max'] = 102400; // Make sure the file is under 1MB
$UPLOAD_SIZES['min'] = 0; // in size
echo 'File: ' . $HTTP_POST_FILES['upload_file']['name'] . '
'
.
'Size: ' . $HTTP_POST_FILES['upload_file']['size'] . '
'
;
// Verify the size and type of the file
$intResult = verify_uploaded_file(
$HTTP_POST_FILES['upload_file']['name'],
$HTTP_POST_FILES['upload_file']['size']);
// The file is not acceptable
if ($intResult != 1) {
$msg_base = $HTTP_POST_FILES['upload_file']['name'] .
' is unacceptable.
'
;
//die() and display error message
if ($intResult == -1) {
die(
$msg_base . 'Reason: File size is too large.');
} elseif (
$intResult == -2) {
die(
$msg_base . 'Reason: File type is not allowed.');
};
// The file has been accepted; verify it and move it to the server :)
if (! move_uploaded_file($HTTP_POST_FILES['upload_file']['tmp_name'], $MOVE_TO_PATH . $HTTP_POST_FILES['upload_file']['name']) ) {
die(
'You did not upload a file or the file could not be moved to ' .
$MOVE_TO_PATH . $HTTP_POST_FILES['upload_file']['name']);
} else {
echo
$HTTP_POST_FILES['upload_file']['name'] . ' was uploaded successfully.';
};
function
verify_uploaded_file($strName, $intSize) {
/* $strName and $intSize are taken from
the uploaded file's information.
Also, make sure that the global variable $UPLOAD_SIZES
and $UPLOAD_TYPES are defined prior to calling
this function. */
// Check file size
if ($intSize < $GLOBALS['UPLOAD_SIZES']['min'] || $intSize > $GLOBALS['UPLOAD_SIZES']['max']) {
return -
1;
};
// Check file type
$arrSegments = split('[.]', $strName); // may contain multiple dots
$strExtension = $arrSegments[count($arrSegments) - 1];
if (
$GLOBALS['UPLOAD_TYPES'][strtoupper($strExtension)] != 1) {
return -
2; // File type not defined/allowed
};
// All tests have passed; this file is valid
return 1;
}
}
?>