The below code works well in my localhost, but gives an error whenever I upload it to my hosting server! :?:
Somebody please suggest me what to do ???
Here is the code:

<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
require('Connections/cn.php');

if(isset($_POST['modify_m']) && $_POST['modify_m']=="Update")
{
	//Update image
	$file_name= $_FILES["file_m"]["name"];
	$file_type= $_FILES["file_m"]["type"];
	$file_size= $_FILES["file_m"]["size"];
	$file_temp= $_FILES["file_m"]["tmp_name"];
	$file_error= $_FILES["file_m"]["error"];
	
	if($file_size > 0)
	{
		//echo $file_type;
		$target_path = $_SERVER['DOCUMENT_ROOT'];
		$target_path = $target_path."images/Food/";
		$target_path = $target_path.$_POST['image_cat_m']."/".$file_name;
	
		if($file_type == "image/png" || "image/jpeg" || "image/bmp")
		{
			move_uploaded_file($file_temp,$target_path);
		}
	}
	//Update data
	$result20=mysql_query("UPDATE productinfo SET Origin='".$_POST["origin_m"]."',Brand='".$_POST["brand_m"]."',Total_price='".$_POST["price_m"]."',Weight='".$_POST["weight_m"]."',Image_Small='".$image_dir."',Product_Name_Eng='".$_POST["name_eng_m"]."',Product_Name_Jp='".$_POST["name_jp_m"]."' WHERE Product_ID='".$_POST["product_id_m"]."'") or die(mysql_errno());
}	
?>

Here is the warning:

Warning: move_uploaded_file(/var/www/vhosts/xxxxx.com/httpdocs/images/Food/Oil/v_oil.bmp) [function.move-uploaded-file]: failed to open stream: Permission denied in /var/www/vhosts/xxxxx.com/httpdocs/product_modify.php on line 32

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpaC1yUA' to '/var/www/vhosts/xxxxx.com/httpdocs/images/Food/Oil/v_oil.bmp' in /var/www/vhosts/xxxxx.com/httpdocs/product_modify.php on line 32

Thanks in advance ...

Ahsan
Tokyo

Hi,

The error is due to your folder having incorrect permissions.

I usually change my uploads directory to be owned by me, and in the same group as the webserver. E.g. chown -R rob:apache uploads/

I also then set the permissions to be read and write for the owner and group, and read for all other users. E.g. chmod -R 664 uploads/

I would suggest never giving execute privileges to an uploads directory, unless you're filtering the file types that can be uploaded, as someone could upload a malicious script and execute it.

R.

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.