Hi i have just finished a tutroial on how to upload a file using PHP however i am getting a very simple error i understand and just cant resolve the error it is
Notice: Use of undefined constant extension - assumed 'extension' in C:\wamp\www\File Upload\upload.php on line 11 (Highlighted in Red)
I know its to do with variable extension not being declared however my PHP coding skills are limited. And help would be great.
upload.php code is
<?php
$uploaddir = "uploads/images";
$allowed_ext = "jpg, JPG, png, gif";
$max_size = "500000000";
$max_width = "4000";
$max_height = "4000";
$extension = pathinfo($_FILES['file']['name']);
$extension = $extension[extension];
$allowed_paths = explode(", ",$allowed_ext);
for($i = 0; $i < count($allowed_paths); $i++){
if ($allowed_paths[$i] == "$extension"){
$ok = "1";
}
}
if ($ok == "1"){
if($_FILES['file']['size'] > $max_size)
{
print "File size is to big !";
exit;
}
if($max_width && $max_height){
list($width, $height, $type, $w)=
getimagesize($_FILES['file']['tmp_name']);
if($width > $max_width || $height > $max_height)
print "File height and or width are too big ! ";
exit;
}
}
if(is_uploaded_file($_FILES['files']['tmp_name']))
{
move_uploaded_file($_FILES['files']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);
print "Your file has been uploaded successfully !";
}
else
{
print "Incorrect file extension !";
}
?>
index.php
<table width="500" height ="500" border="5" align = "center" cellpadding="10">
<tr>
<tr>
<td valign="top">
<form action ="upload.php" method = "post" enctype="multipart/form-data">
File:<input type="file" name ="file" size "30"><input type="submit" value="upload">
</form>
</td>
</tr>
</table>
Any suggestions would be much appricated
Thanks in Advance
Notice: Use of undefined constant extension - assumed 'extension' in C:\wamp\www\File Upload\upload.php on line 11 (Highlighted in Red)
I know its to do with variable extension not being declared however my PHP coding skills are limited. And help would be great.
upload.php code is
<?php
$uploaddir = "uploads/images";
$allowed_ext = "jpg, JPG, png, gif";
$max_size = "500000000";
$max_width = "4000";
$max_height = "4000";
$extension = pathinfo($_FILES['file']['name']);
$extension = $extension[extension];
$allowed_paths = explode(", ",$allowed_ext);
for($i = 0; $i < count($allowed_paths); $i++){
if ($allowed_paths[$i] == "$extension"){
$ok = "1";
}
}
if ($ok == "1"){
if($_FILES['file']['size'] > $max_size)
{
print "File size is to big !";
exit;
}
if($max_width && $max_height){
list($width, $height, $type, $w)=
getimagesize($_FILES['file']['tmp_name']);
if($width > $max_width || $height > $max_height)
print "File height and or width are too big ! ";
exit;
}
}
if(is_uploaded_file($_FILES['files']['tmp_name']))
{
move_uploaded_file($_FILES['files']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);
print "Your file has been uploaded successfully !";
}
else
{
print "Incorrect file extension !";
}
?>
index.php
<table width="500" height ="500" border="5" align = "center" cellpadding="10">
<tr>
<tr>
<td valign="top">
<form action ="upload.php" method = "post" enctype="multipart/form-data">
File:<input type="file" name ="file" size "30"><input type="submit" value="upload">
</form>
</td>
</tr>
</table>
Any suggestions would be much appricated
Thanks in Advance