/    Sign up×
Bounties /Pin to ProfileBookmark

Tried to add a picture with product data in the database, but it failed and errors were displayed.

Hello. I am working on an e-commerce project. Using the Admin panel, I tried to add a picture with product data in the database, but it failed and errors were displayed.

// Warning: move_uploaded_file(product_images/dress.jpeg): failed to open stream: Permission denied in /opt/lampp/htdocs/project/admin_area/includes/insert_product.php on line 115

Warning: move_uploaded_file(): Unable to move ‘/opt/lampp/temp/php48ULD8’ to ‘product_images/dress.jpeg’ in /opt/lampp/htdocs/project/admin_area/includes/insert_product.php on line 115


I tried to add different permissions, but it didn’t solve anything


 $product_title = $_POST['product_title'];
 $product_cat = $_POST['product_cat'];
 $product_brand = $_POST['product_brand'];
 $product_price = $_POST['product_price'];
 $product_desc = trim(mysqli_real_escape_string($con,$_POST['product_desc']));
 $product_keywords = $_POST['product_keywords']; 
 // Getting the image from the field
 $product_image = $_FILES['product_image']['name'];
 $product_image_tmp = $_FILES['product_image']['tmp_name'];
 $insert_product = " insert into products (product_cat,product_brand,product_title,product_price,product_desc,product_image,product_keywords) 
 values ('$product_cat','$product_brand','$product_title','$product_price','$product_desc','$product_image','$product_keywords') ";

 $insert_pro = mysqli_query($con, $insert_product);
 echo "<script>alert('Product Has Been inserted successfully!')</script>";
	//echo "<script>window.open('index.php?insert_product','_self')</script>";

to post a answer

4 Replies

Davinci•003 auto-replyIt sounds like you are running into a permissions issue. It looks like the user that is running the web server does not have permission to write to the directory where you are trying to upload the image. You can try changing the permissions of the directory to allow the web server user to write to it. You can do this by running the command chmod -R 755 product_images in the directory where the product_images directory is located. This should give the web server user the necessary permissions to write to the directory.

Was this helpful?

Copy linkTweet thisAlerts:
@preizeingunaauthorMay 23.2023 — I will try
Copy linkTweet thisAlerts:
@luffyMay 24.2023 — Are you an particular Admin panel template?
Copy linkTweet thisAlerts:
@KnowNMay 25.2023 — Because you want to use the move_uploaded_file() function into insert_product you should first get in the current path.

I'll consider that the product_images will be into the admin_area folder.

The solution for this will be:

move_uploaded_file($product_image_tmp, '../product_images/' . $product_image);
@SempervivumAgree, although the error message says "Permission denied" I recommend to check this either.May 25.2023


Help @preizeinguna spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 9.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ

legal: ({
terms: of use,
privacy: policy
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
recent_tips: (
tipper: @ddiebold17,
tipped: article
amount: 1000 SATS,

tipper: @Mqlinka19,
tipped: live stream
amount: 4900 SATS,

tipper: @Mqlinka19,
tipped: article
amount: 10 SATS,