[SOLVED] file uploading
Posted: Thu Jan 06, 2005 2:36 am
feyd | Help us, help you. Please use
and the code to upload the files
img1 uploads fine but img2 doesn't go into the if statement:
no matter what image extension the file is.
Can anyone see the reason why? Getting really frustrating
feyd | Help us, help you. Please use
Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Can anyone help with the following (details through post):Code: Select all
<form action="p_addphotos.php" method="POST" name="addphoto" ENCTYPE="multipart/form-data">
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr>
<td align=left valign=top><b>Thumbnail:</b></td>
<td align=left valign=top>
<INPUT TYPE="file" NAME="img1" SIZE="50"></p>
<INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="8000" />
The size of the thumbnail must be exactly 100 by 100 pixels and must be in the format of *.jpg, *.jpeg or *.gif
</td>
</tr>
<tr>
<td align=left valign=top><b>Photo:</b></td>
<td align=left valign=top>
<INPUT TYPE="file" NAME="img2" SIZE="50"></p>
The image must be in the format of *.jpg, *.jpeg or *.gif
</td>
</tr>Code: Select all
$uploaddir = 'photos/thumbnails/';
$uploadfile1 = $uploaddir . $_FILES['img1']['name'];
$filetypes = array("image/jpg","image/gif","image/jpeg","image/pjpeg");
$imageinfo = getimagesize($_FILES['img1']['tmp_name']);
// upload the file only if the file type is gif or jpg.
if(in_array(strtolower($_FILES['img1']['type']),$filetypes) && $imageinfo[0] = 100 && $imageinfo[1] = 100)
{
// let us read all the files in the directory and rename the file, if exists.
if (file_exists($uploadfile1))
{
$path_parts = pathinfo($uploadfile1);
$uploadfile1 = $uploaddir.(substr($_FILES['img1']['name'],0,(strlen($_FILES['img1']['name'])-(strlen($path_parts['extension'])+1))).date("YmdHis").".".$path_parts['extension']);
}
if (move_uploaded_file($_FILES['img1']['tmp_name'], $uploadfile1))
{
$FileSuccess1 = 1;
}
else
{
$FileSuccess1 = 0;
}
}
$uploaddir = 'photos/';
$uploadfile2 = $uploaddir . $_FILES['img2']['name'];
$filetypes = array("image/jpg","image/gif","image/jpeg","image/pjpeg");
// upload the file only if the file type is gif or jpg.
if(in_array(strtolower($_FILES['img2']['type']),$filetypes))
{
// let us read all the files in the directory and rename the file, if exists.
if (file_exists($uploadfile2))
{
$path_parts = pathinfo($uploadfile2);
$uploadfile2 = $uploaddir.(substr($_FILES['img2']['name'],0,(strlen($_FILES['img2']['name'])-(strlen($path_parts['extension'])+1))).date("YmdHis").".".$path_parts['extension']);
}
if (move_uploaded_file($_FILES['img2']['tmp_name'], $uploadfile2))
{
$FileSuccess2 = 1;
}
else
{
$FileSuccess2 = 0;
}
}Code: Select all
if(in_array(strtolower($_FILES['img2']['type']),$filetypes))Can anyone see the reason why? Getting really frustrating
feyd | Help us, help you. Please use
Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]