Unwanted
Member
- Jan 10, 2014
- 58
- 21
Nahitaji kuapload picha yenye ukubwa wa zaidi ya 4MB kwenye server lakini hizi code zinaupload chini ya 512kb msaada tafadhali kwa mwenye uelewa wa php.
<?php
$sqlw = mysql_query("select status from message where status='0'");
$num = mysql_num_rows($sqlw);
//error_reporting(0);
if(isset($_POST['btnsubmit'])){
$allowedExts = array("jpg", "jpeg", "gif", "png");
$new_file = uniqid().$_FILES["file"]["name"];
$extension = end(explode(".", $new_file));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < (1024000))
&& in_array($extension, $allowedExts)
)
{
if ($_FILES["file"]["error"] > 0)
{
$errinfo = "<div class='error_box'>Return Code: " . $_FILES["file"]["error"] . "</div>";
}
elseif (file_exists("category/" . $new_file))
{
$errinfo = "<div class='error_box'>". $new_file . " already exists.</div> ";
}
else
{
$name=mysql_escape_string(strip_tags($_POST['name']));
$quantity=mysql_escape_string(strip_tags($_POST['quantity']));
$file="category/" .$new_file;
// checking empty fields
if(empty($quantity) || empty($name) || !is_numeric($quantity))
{
if(empty($name))
{
$errinfo = "<div class='error_box'>Iterm Name field is empty.</div>";
}
if(empty($quantity))
{
$errinfo = "<div class='error_box'>Quantity field is empty.</div>";
}
//if quantity is numeric
if(!is_numeric($quantity))
{
$errinfo = "<div class='error_box'>Quantity entered was not numeric.</div>";
}
}else{
$sel = mysql_query("INSERT INTO categories (categories, status, quantity, removed, location) VALUES('$name','0','$quantity','0','$file')");
$sel1 = move_uploaded_file($_FILES["file"]["tmp_name"],"category/" . $new_file);
if(($sel && $sel1)==true){
header("location:home.php");
}else{
$errinfo = "<div class='error_box'>Iterm failed, Please try again!.</div>";
}
}
}
}
else
{
$errinfo = "<div class='error_box'>Invalid File</div>";
}
}
?>
Natanguliza shukrani kwenu wadau.
<?php
$sqlw = mysql_query("select status from message where status='0'");
$num = mysql_num_rows($sqlw);
//error_reporting(0);
if(isset($_POST['btnsubmit'])){
$allowedExts = array("jpg", "jpeg", "gif", "png");
$new_file = uniqid().$_FILES["file"]["name"];
$extension = end(explode(".", $new_file));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < (1024000))
&& in_array($extension, $allowedExts)
)
{
if ($_FILES["file"]["error"] > 0)
{
$errinfo = "<div class='error_box'>Return Code: " . $_FILES["file"]["error"] . "</div>";
}
elseif (file_exists("category/" . $new_file))
{
$errinfo = "<div class='error_box'>". $new_file . " already exists.</div> ";
}
else
{
$name=mysql_escape_string(strip_tags($_POST['name']));
$quantity=mysql_escape_string(strip_tags($_POST['quantity']));
$file="category/" .$new_file;
// checking empty fields
if(empty($quantity) || empty($name) || !is_numeric($quantity))
{
if(empty($name))
{
$errinfo = "<div class='error_box'>Iterm Name field is empty.</div>";
}
if(empty($quantity))
{
$errinfo = "<div class='error_box'>Quantity field is empty.</div>";
}
//if quantity is numeric
if(!is_numeric($quantity))
{
$errinfo = "<div class='error_box'>Quantity entered was not numeric.</div>";
}
}else{
$sel = mysql_query("INSERT INTO categories (categories, status, quantity, removed, location) VALUES('$name','0','$quantity','0','$file')");
$sel1 = move_uploaded_file($_FILES["file"]["tmp_name"],"category/" . $new_file);
if(($sel && $sel1)==true){
header("location:home.php");
}else{
$errinfo = "<div class='error_box'>Iterm failed, Please try again!.</div>";
}
}
}
}
else
{
$errinfo = "<div class='error_box'>Invalid File</div>";
}
}
?>
Natanguliza shukrani kwenu wadau.