Php 如何使用web service prestashop删除图像
大家好,像标题说我不知道如何删除图像。我可以添加和更新它们,但我找不到删除它们的方法 这是我用来更新和添加图像的代码:Php 如何使用web service prestashop删除图像,php,web-services,prestashop-1.6,Php,Web Services,Prestashop 1.6,大家好,像标题说我不知道如何删除图像。我可以添加和更新它们,但我找不到删除它们的方法 这是我用来更新和添加图像的代码: $idProduct = 54; $idImage = 26; //$url = "http://192.168.1.124/prestashop/api/images/products/" . $idProducto . "/"; //Uncomment this line to add an image $ur
$idProduct = 54;
$idImage = 26;
//$url = "http://192.168.1.124/prestashop/api/images/products/" . $idProducto . "/"; //Uncomment this line to add an image
$url = "http://192.168.1.124/prestashop/api/images/products/" . $idProduct . "/".$idImage."?ps_method=PUT";
$image_path = 'C:\\camisa2.jpg';
$key = 'XXXXXXXXXXXXXXXXXXX'; //Prestashop key
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
//curl_setopt($ch, CURLOPT_PUT, true); // Un-commet to edit an image
curl_setopt($ch, CURLOPT_USERPWD, $key.':');
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$image_path.';type=image/jpg'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
echo "<h3>Image Updated</h3>";
$idProduct=54;
$idImage=26;
//$url=”http://192.168.1.124/prestashop/api/images/products/" . $idProducto。"/"; //取消对此行的注释以添加图像
$url=”http://192.168.1.124/prestashop/api/images/products/" . $idProduct。“/”$idImage。”?ps_方法=放置”;
$image_path='C:\\camisa2.jpg';
$key='xxxxxxxxxxxxxxxx'//预拔键
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_POST,true);
//curl_setopt($ch,CURLOPT_PUT,true);//取消命令以编辑图像
curl_setopt($ch,CURLOPT_USERPWD,$key.:');
curl_setopt($ch,CURLOPT_POSTFIELDS,array('image'=>'@'.$image_path.';type=image/jpg');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$result=curl\u exec($ch);
卷曲关闭($ch);
回声“图像更新”;
任何帮助都将不胜感激
问候语我在PrestashopWebService库中找到了一个删除对象的示例。 希望它能帮助您:
// Here we define constants /!\ You need to replace this parameters
define('DEBUG', true);
define('PS_SHOP_PATH', 'http://www.myshop.com/');
define('PS_WS_AUTH_KEY', 'ZQ88PRJX5VWQHCWE4EE7SQ7HPNX00RAJ');
require_once('./PSWebServiceLibrary.php');
if (isset($_GET['DeleteID']))
{
//Deletion
echo '<h1>Customers Deletion</h1><br>';
// We set a link to go back to list
echo '<a href="?">Return to the list</a>';
try
{
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
// Call for a deletion, we specify the resource name and the id of the resource in order to delete the item
$webService->delete(array('resource' => 'customers', 'id' => intval($_GET['DeleteID'])));
// If there's an error we throw an exception
echo 'Successfully deleted !<meta http-equiv="refresh" content="5"/>';
}
catch (PrestaShopWebserviceException $e)
{
// Here we are dealing with errors
$trace = $e->getTrace();
if ($trace[0]['args'][0] == 404) echo 'Bad ID';
else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
else echo 'Other error<br />'.$e->getMessage();
}
}
else
{
// Else get customers list
}
//这里我们定义常量//!\您需要替换此参数
定义('DEBUG',true);
定义('PS\U SHOP\U PATH','http://www.myshop.com/');
定义('PS_WS_AUTH_KEY','ZQ88PRJX5VWQHCWE4EE7SQ7HPNX00RAJ');
需要_一次('./PSWebServiceLibrary.php');
如果(isset($\u GET['DeleteID']))
{
//删除
回显“客户删除
”;
//我们设置了一个返回列表的链接
回声';
尝试
{
$webService=新的PrestaShopWebservice(PS\u SHOP\u路径,PS\u WS\u AUTH\u密钥,调试);
//调用删除时,我们指定资源名称和资源id以删除该项
$webService->delete(数组($resource'=>'customers','id'=>intval($\u GET['DeleteID']));
//如果出现错误,我们将抛出异常
echo“已成功删除!”;
}
捕获(PrestaShopWebserviceException$e)
{
//这里我们处理的是错误
$trace=$e->getTrace();
如果($trace[0]['args'][0]==404)回显'Bad ID';
else if($trace[0]['args'][0]==401)回显'Bad auth key';
else回显“其他错误
”。$e->getMessage();
}
}
其他的
{
//否则,请获取客户列表
}
来源:我在PrestashopWebService库中找到了一个删除对象的示例。 希望它能帮助您:
// Here we define constants /!\ You need to replace this parameters
define('DEBUG', true);
define('PS_SHOP_PATH', 'http://www.myshop.com/');
define('PS_WS_AUTH_KEY', 'ZQ88PRJX5VWQHCWE4EE7SQ7HPNX00RAJ');
require_once('./PSWebServiceLibrary.php');
if (isset($_GET['DeleteID']))
{
//Deletion
echo '<h1>Customers Deletion</h1><br>';
// We set a link to go back to list
echo '<a href="?">Return to the list</a>';
try
{
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
// Call for a deletion, we specify the resource name and the id of the resource in order to delete the item
$webService->delete(array('resource' => 'customers', 'id' => intval($_GET['DeleteID'])));
// If there's an error we throw an exception
echo 'Successfully deleted !<meta http-equiv="refresh" content="5"/>';
}
catch (PrestaShopWebserviceException $e)
{
// Here we are dealing with errors
$trace = $e->getTrace();
if ($trace[0]['args'][0] == 404) echo 'Bad ID';
else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
else echo 'Other error<br />'.$e->getMessage();
}
}
else
{
// Else get customers list
}
//这里我们定义常量//!\您需要替换此参数
定义('DEBUG',true);
定义('PS\U SHOP\U PATH','http://www.myshop.com/');
定义('PS_WS_AUTH_KEY','ZQ88PRJX5VWQHCWE4EE7SQ7HPNX00RAJ');
需要_一次('./PSWebServiceLibrary.php');
如果(isset($\u GET['DeleteID']))
{
//删除
回显“客户删除
”;
//我们设置了一个返回列表的链接
回声';
尝试
{
$webService=新的PrestaShopWebservice(PS\u SHOP\u路径,PS\u WS\u AUTH\u密钥,调试);
//调用删除时,我们指定资源名称和资源id以删除该项
$webService->delete(数组($resource'=>'customers','id'=>intval($\u GET['DeleteID']));
//如果出现错误,我们将抛出异常
echo“已成功删除!”;
}
捕获(PrestaShopWebserviceException$e)
{
//这里我们处理的是错误
$trace=$e->getTrace();
如果($trace[0]['args'][0]==404)回显'Bad ID';
else if($trace[0]['args'][0]==401)回显'Bad auth key';
else回显“其他错误
”。$e->getMessage();
}
}
其他的
{
//否则,请获取客户列表
}
来源:试试这个:
$url = "http://192.168.1.124/prestashop/api/images/products/" . $idProduct . "/".$idImage."?ps_method=DELETE";
试试这个:
$url = "http://192.168.1.124/prestashop/api/images/products/" . $idProduct . "/".$idImage."?ps_method=DELETE";
操作:HTTP DELETE URL:www.shop.com/api/images/products///如果您正在使用webservice api,则resource=“images/products/”id=i.e.$webservice->DELETE(数组('resource'=>'images/products/,'id'=>”);操作:HTTP DELETE URL:www.shop.com/api/images/products///如果您正在使用webservice api,则resource=“images/products/”id=i.e.$webservice->DELETE(数组('resource'=>'images/products/,'id'=>”);