Forum Moderators: coopster
<?php
$file_dir="images/";
$file_url=$Image;
if(isset($Image))
{
if($Image_type=="image/gif")
{
copy($Image,"$file_dir/$Image_name")or die("Couldnt copy image");
}
}
//Reads and prints the contents of the table.
$Image="<p><a href=\"images/$Image_name\" target=\"_blank\"><img src=\"images/$Image_name\" width=\"180\" height=\"180\" border=\"0\"></a></p>\n";
function read_and_print($Name,$Image,$Description)
{
$result=mysql_query("SELECT * FROM cus_gallery");
while($field=mysql_fetch_array($result))
{
print("<table id=\"pbslayout\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">\n<tr>\n<td>\n");
print"\t<div id=\"top\"><p id=\"title\">$field[Name]</p></div>\n";
print"<div id=\"mid\">$field[Image]\n";
print"<p id=\"text\">$field[Description]</p></div>\n";
print("<div id=\"bot\"></div>\n");
print("</td>\n</tr>\n</table>\n");
print"<hr>";
}
}
if (isset($Name)&&isset($Image)&&isset($Description))
{
if($Name=="")
{
$Name="No Name";
}
if($Description=="Enter a description of the product here")
{
$Description="No description";
}
$dberror="";
$ret=add_to_database($Name,$Image,$Description,$dberror);
if(!$ret)
print"Error: $dberror<BR>";
else
print write_form();
print"Thank you very much<p>Here is the information in the database:<hr>";
print read_and_print($Name,$Image,$Description);
}
else
{
write_form();
}
function add_to_database($Name,$Image,$Description,&$dberror)
{
$user="******";
$pass="******";
$db="displays";
$link=mysql_pconnect("localhost",$user,$pass);
if(!$link)
{
$dberror="couldnt connect to MySQL server";
return false;
}
if(!mysql_select_db($db,$link))
{
$dberror=mysql_error();
return false;
}
$query="INSERT INTO cus_gallery(Name,Image,Description)
values('$Name','$Image','$Description')";
if(!mysql_query($query,$link))
{
$dberror=mysql_error();
return false;
}
return true;
}
function write_form()
{
global$PHP_SELF;
print"<form action=\"$PHP_SELF\" method=\"POST\" enctype=\"multipart/form-data\"><a href=\"#\" name=\"top\"></a>\n";
print"<input type=\"text\" name=\"Name\">";
print" :Enter the product title here.<p>\n";
print"<input type=\"file\" name=\"Image\">\n";
print"<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"102400\">\n";
print" : Choose the products display image here.<p>\n";
print"<textarea type=\"text\" cols=\"50\" rows=\"10\" name=\"Description\">\n";
print"Enter a description of the product here";
print"</textarea><br>\n";
print"<input type=\"submit\" value=\"submitit!\">\n</form>\n";
}
?>
I have tried using the following line:
if($Image_type=="image/gif" or $Image_type=="image/jpeg")
But the results are still the same, no doubt i have missed something here, does anyone have a possible solution?
I have tried using the following line:if($Image_type=="image/gif" or $Image_type=="image/jpeg")
But the results are still the same, no doubt i have missed something here, does anyone have a possible solution?
If you want to allow all types of images, go this route:
if (substr($Image_type, 0, 5)== 'image'))
Ive tried both:
if($Image_type=="image/gif" or $Image_type=="image/jpg")
and:
if($Image_type=="image/gif" or $Image_type=="image/jpeg")
But still the same results, not to worry im sure ill get there... thanks anyways
Ok the situation has been resolved thanks to those who participated in providing an answer... ;)
<input name="userfile" type="file" accept="application/pdf" />
text/plain
text/html
image/gif
etc.
This attribute specifies a comma-separated list of content types that a server processing this form will handle correctly. User agents may use this information to filter out non-conforming files when prompting a user to select files to be sent to the server.
The second part would be pretty nice if browsers would look things over for you first. Wish in one hand, ...