Forum Moderators: coopster
In my upload script I have:
if(is_uploaded_file($_FILES['userfile']['tmp_name']))
{
..do some code, etc.
}
There seems to be nothing in the $_FILES array after selecting a file and clicking submit. Any ideas why?
All I get is this when trying to echo some of the $_FILES variables:
File Array is Array bytes, i.e. the word Array is just being printed instead of the relevant info.
<?
// the upload function
function upload()
{
$maxsize = 1000000;
print_r($_FILES);
if(is_uploaded_file($_FILES['userfile']['tmp_name']))
{
// check the file is less than the maximum file size
if($_FILES['userfile']['size'] < $maxsize)
{
// prepare the image for insertion
$imgData =addslashes (file_get_contents($_FILES['userfile']['tmp_name']));
// $imgData = addslashes($_FILES['userfile']);
// get the image info..
$size = getimagesize($_FILES['userfile']['tmp_name']);
// put the image in the db...
$sql = "INSERT INTO Tracks (
TrackID, Artist, Title, Mix, LabelID, GenreID, ReleaseDate, Picture,
192Path, 300Path, WavPath, SamplePath, Price, PictureSize, Image'name' )
VALUES (
1, '', '', '', 1, 1, now(), '{$imgData}', '', '', '', '', 0.80,
'{$size[3]}', '{$_FILES['userfile']['name']}' )";
// insert the image
if(!mysql_query($sql))
{
echo 'Unable to upload file';
}
}
else
{
// if the file is not less than the maximum allowed, print an error
echo "
<div>File exceeds the Maximum File limit</div>
<div>Maximum File limit is ".$maxsize."</div>
<div>File ".$_FILES['userfile']['name']." is ".$_FILES['userfile']['size']." bytes</div>
<hr />";
}
}
else
{
echo "
<div>File wasn't uploaded</div>
<hr />";
}
}
?>
Is there some sort of function that I need to use to convetr the file back into an image or some sort of header?