<?php

 require_once('../vendor/autoload.php');

if (!isset($_POST["cart_payload"])) {
    echo "PAYLOAD NOT SET";
}

$items = json_decode($_POST["cart_payload"], true);
$line_items = array();
foreach ($items as $item) {
    $line_items[] = array(

$target = 'images/'; 
$target = $target . basename( $_FILES['image']['name'])
        'name' => $item["title"],
        'image' => $FILES["image"],
        'amount' => $item["price"]*100,
        'currency' => 'gbp',
        'quantity' => $item["quantity"],
    );
}

// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
 \Stripe\Stripe::setApiKey('sk_test_Bv1CxPqIn7LFeZ8MGvUKHu0h00rFUx2JlI');

$session = \Stripe\Checkout\Session::create([
    'payment_method_types' => ['card'],
    'line_items' => $line_items,
    'success_url' => 'https://skatelandnottingham.co.uk',
    'cancel_url' => 'https://skatelandnottinghamk.co.uk/events/',
 ]);

Dani AI

Generated

— the posted snippet has three separate problems that explain both parse warnings and the likely "failed to open stream" behavior mentioned by : (1) PHP syntax/placement errors (the $target assignment is injected inside the array construction and a few semicolons/variables are wrong), (2) incorrect use of the upload array (using $FILES instead of $_FILES, not moving tmp_name), and (3) passing an uploaded file resource (or a server path) to Stripe instead of a public URL or a Stripe File ID. move_uploaded_file will fail if the destination does not exist or is unwritable; PHP’s file-upload rules and common reasons for “failed to open stream” are documented. (php.net)

Stripe Checkout will not accept a PHP $_FILES handle — it needs either a public HTTPS URL (or a Stripe File ID) inside the product images field, and modern Checkout expects inline items using price_data / product_data (not ad-hoc name/amount fields). The images must be reachable by Stripe’s servers and sent as an array of URLs (or set on a product). ()

A minimal, safe workflow (handle uploads first, produce a public URL, then build line_items) — example:

// (1) handle upload
$uploads = __DIR__ . '/public_images/';
if (!is_dir($uploads)) mkdir($uploads, 0755, true);
if ($_FILES['image']['error'] === UPLOAD_ERR_OK) {
  $tmp = $_FILES['image']['tmp_name'];
  $name = basename($_FILES['image']['name']);
  $dest = $uploads . $name;
  if (!move_uploaded_file($tmp, $dest)) {
    error_log('upload move failed');
  } else {
    $publicUrl = (isset($_SERVER['HTTPS']) ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . '/public_images/' . rawurlencode($name);
  }
}

// (2) build line item using price_data/product_data.images
$line_items[] = [
  'price_data' => [
    'currency' => 'gbp',
    'unit_amount' => intval($item['price'] * 100),
    'product_data' => [
      'name' => $item['title'],
      'images' => [$publicUrl],
    ],
  ],
  'quantity' => intval($item['quantity']),
];

Key checks and tips: the upload form must use enctype="multipart/form-data" and $_FILES should be inspected via its error and tmp_name fields (don’t move the name field). Confirm the destination directory exists and is writable by the web process; check open_basedir / upload_tmp_dir if the host imposes restrictions. Finally, do not rely on the success redirect to confirm payment — use the Checkout webhook (checkout.session.completed) for fulfillment. (php.net)

Welcome to DaniWeb. I wonder if you clicked the submission button too soon and forgot to add a question such as:

Why do I get the error "failed to open stream"?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.