I’ve been working on this for a few days now and I’m stuck on this part. Every time a file is uploaded to the system, it completes the insert into the database, the file gets uploaded, but then an error is thrown in my system and the user gets logged out. I followed the example from file upload and everything looks correct, but something is not working properly:
function add_insert($data)
{
global $g;
try
{
$upload_file_path = $data[“params”][“fileupload”];
unset($data[“params”][“fileupload”]);
// if file is uploaded
if ($upload_file_path)
{
$data[“params”][“fname”] = pathinfo(realpath($upload_file_path), PATHINFO_BASENAME);
$file_content = file_get_contents(realpath($upload_file_path), true);
// check if file ext allowed
$ext = pathinfo(realpath($upload_file_path), PATHINFO_EXTENSION);
if ($ext <> “gif” && $ext <> “jpg” && $ext <> “png” && $ext <> “webp”)
{
unlink(realpath($upload_file_path));
phpgrid_error(“Only pdf, gif, jpg, txt, doc, bmp, png files are allowed!”);
}
// insert in db
// $g = new jqgrid();
$g->execute_query(“insert into oems (oemname, oemimagename, oemenabled) values (‘{$data[“params”][“oemname”]}’, ‘{$data[“params”][“fname”]}’, 1)”);
}
}
catch (Exception $ex)
{
}
}
Possibly duplicate.
Answered here: https://www.gridphp.com/support/questions/on_insert-with-image-problem/#answer-12098