0) { if($type === 'default') $img_pub_path = _PS_IMG_DIR_."configurator/field/admin/"; else $img_pub_path = _PS_IMG_DIR_."configurator/field/customer/"; if($prev) { if (filter_var($prev, FILTER_SANITIZE_URL) !== false) { $image_name = pathinfo($prev, PATHINFO_BASENAME); $image = $img_pub_path . $image_name; if (!is_dir($image) && file_exists($image)) { @unlink($image); } } } $filename = $_FILES['file']['name']; $tmpname = $_FILES['file']['tmp_name']; $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); $time = time(); $upload_path = $img_pub_path . $time . '.' . $extension; if($type === 'default') $img_pub_path_uri = _PS_IMG_."configurator/field/admin/"; else $img_pub_path_uri = _PS_IMG_."configurator/field/customer/"; if(move_uploaded_file($tmpname, $upload_path)) { @chmod($upload_path, 0664); } $result = Media::getMediaPath($img_pub_path_uri.$time . '.' . $extension); die($result); } else if (isset($file) && $file) { $img_pub_path = _PS_IMG_DIR_."configurator/field/customer/"; if($prev) { if (filter_var($prev, FILTER_SANITIZE_URL) !== false) { $image_name = pathinfo($prev, PATHINFO_BASENAME); $image = $img_pub_path . $image_name; if (!is_dir($image) && file_exists($image)) { @unlink($image); } } } list($type_img, $file) = explode(';', $file); list(, $file) = explode(',', $file); $file = base64_decode($file); $type_img = explode(':', $type_img); $type_img = explode('/', $type_img[1]); $extension = $type_img[1]; $time = time(); $upload_path = $img_pub_path . $time . '.' . $extension; $img_pub_path_uri = _PS_IMG_."configurator/field/customer/"; // upload cropped image to server file_put_contents($upload_path, $file); $result = Media::getMediaPath($img_pub_path_uri.$time . '.' . $extension); die($result); }