Example #1
0
            preg_match($pattern, $images[$k], $matches);
            $ext = $matches[0];
            if ($images[$k] == $main_img) {
                $path = "../my_images/news" . $insert_id . '-main.' . $ext;
            } else {
                $path = "../my_images/news" . $insert_id . '_' . $index . '.' . $ext;
                $index++;
            }
            if (!is_file($path)) {
                copy('../temp/' . $images[$k], $path);
            }
        }
        delete_uploaded_images();
    }
} elseif ($type == 'update') {
    $id = $_POST['id'];
    $query = "UPDATE news SET content='" . $content . "',title='" . $title . "',video='" . $video . "',heading='" . $heading . "',lang='" . $language . "' WHERE id='" . $id . "'";
    mysqli_query($conn, $query);
    $image = get_picture();
    if ($image) {
        $pattern = '~(jpg|jpeg|gif|png)~';
        preg_match($pattern, $image, $matches);
        $ext = $matches[0];
        $path = "../my_images/news" . $id . '.' . $ext;
        if (!is_file($path)) {
            unlink($path);
        }
        copy('../temp/' . $image, $path);
        delete_uploaded_image();
    }
}
Example #2
0
function copy_image($path)
{
    $arr = explode('/', $path);
    delete_uploaded_image();
    if (isset($arr[2])) {
        copy($path, '../temp/' . $arr[2]);
    }
}