שאלה

DAVC22

New member
שאלה

יש לי את הקוד הבא:

set_error_handler("customError");
function customError($errno, $errstr)
{
$Rtrn['ErrDes'] = "Error: [$errno] $errstr";
$Rtrn['error'] = false;
echo json_encode($Rtrn);

}

$con = mysql_connect("localhost","root","1");
mysql_query("SET NAMES 'utf8'") or die(mysql_error());
if (!$con)
{
die('Could not connect: ' . mysql_error());
}



$allowedExts = array("jpeg", "jpg", "png");
$fileStr = explode(".", $_FILES["file"]["name"]);
$extension = end($fileStr);
if ((($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png")) && in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{

$Rtrn['error'] = true;
$Rtrn['ErrDes'] = "Error: " . $_FILES["file"]["error"];
echo json_encode($Rtrn);
exit();
}

}
else {

$Rtrn['error'] = true;
$Rtrn['ErrDes'] = " you can upload only jpg and png " ;
echo json_encode($Rtrn);
exit();

}

move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);


כשהוא עובד באופן עצמאי אז אין בעיה.

הוא גם עובד מ AJAX אבל הבעיה שהוא לא מחזיר DATA על שגיאות

תודה מראש על כל עזרה
 
למעלה