You can't do that over http, you need to move the file on the file system.
You are trying to write it to http://localhost*** you need to write it to c:\wamp\www****
string(50) "http://localhost/coffee-blend/images/dessert-5.jpg" Warning: move_uploaded_file(http://localhost/coffee-blend/images/dessert-5.jpg): Failed to open stream: HTTP wrapper does not support writeable connections in C:\xampp\htdocs\coffee-blend\admin-panel\products\add-product.php on line 24
Warning: move_uploaded_file(): Unable to move "C:\xampp\tmp\php89B8.tmp" to "http://localhost/coffee-blend/images/dessert-5.jpg" in C:\xampp\htdocs\coffee-blend\admin-panel\products\add-product.php on line 24
if (isset($_POST['submit']) && $_POST) {
$productName = $_POST['product_name'];
$productDesc = $_POST['product_desc'];
$productCat = $_POST['product_cat'];
$productPrice = $_POST['product_price'];
$target_dir = "" . APPURL . "images/";
$image_name = basename($_FILES['product_img']['name']);
$target_file = $target_dir . $image_name;
var_dump($target_file); //string(50) "http://localhost/coffee-blend/images/dessert-5.jpg"
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
if ($uploadOk == 1) {
if (move_uploaded_file($_FILES["product_img"]["tmp_name"], $target_file)) {
echo "File uploaded successfully.";
$add_product = $conn->prepare("INSERT INTO products(name,image,description,category,price) VALUES(:name,:image,:description,:category,:price)");
if ($add_product->execute(
[
'name' => $productName,
'image' => $image_name,
'description' => $productDesc,
'category' => $productCat,
'price' => $productPrice
]
)) {
$message = "Product created successfully";
}
} else {
$message = "There was an error uploading your file.";
}
} else {
$message = "File was not uploaded due to validation errors.";
}
}
not able to understand what is exactly happening
You can't do that over http, you need to move the file on the file system.
You are trying to write it to http://localhost*** you need to write it to c:\wamp\www****
Please or to participate in this conversation.