自定义Magento产品PHP copy imagepng无法写入文件夹

问题描述 投票:0回答:1

下午好。我被要求帮助弄清楚为什么在创建自定义座位后产品图像没有在购物车中正确显示。这段代码是继承的,所以老实说我不完全理解它是如何工作的,但我确实想要弄清楚它。任何帮助,将不胜感激。

如果您访问此link,您可以看到代码。

我设法找到了运行该页面的文件,可以从这个Dropbox link下载它们。

save-custom.phtml

$style = $_REQUEST['style'];
$ribs1 = $_REQUEST['ribs'];
$top1 = $_REQUEST['top'];
$side1 = $_REQUEST['side'];
$ribs1 = explode(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB), $_REQUEST['ribs']);
$ribs = $ribs1[1];
$top1 = explode(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB), $_REQUEST['top']);
$top = $top1[1];
$side1 = explode(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB), $_REQUEST['side']);
$side = $side1[1];
//die($ribs ."   |  " .$ribs1[0]);
//$side = "black_sides.png";
//$top = "green_top.png";
$newCustomPhotoName = $_REQUEST['newPict'];

if ($style == 'ribbed') {
    $first = $top;
    $second = $ribs;
    $photo = imagecreatefrompng("$first");
    $frame = imagecreatefrompng("$second");
    $w = imagesx($photo);
    $h = imagesy($photo);

    imagealphablending($photo, true);
    imagesavealpha($photo, true);
    imagealphablending($frame, true);
    imagesavealpha($frame, true);

    imagecopy($photo, $frame, 0, 0, 0, 0, $w, $h);
    imagepng($photo, $newCustomPhotoName);


    $photo = imagecreatefrompng("$newCustomPhotoName");
    $frame = imagecreatefrompng("$side");
    $w = imagesx($photo);
    $h = imagesy($photo);

    imagealphablending($photo, true);
    imagesavealpha($photo, true);
    imagealphablending($frame, true);
    imagesavealpha($frame, true);
    imagecopy($photo, $frame, 0, 0, 0, 0, $w, $h);
    imagepng($photo, $newCustomPhotoName);
} else {
    $first = $side;
    $second = $top;
    $photo = imagecreatefrompng("$first");
    $frame = imagecreatefrompng("$second");
    $w = imagesx($photo);
    $h = imagesy($photo);

    imagealphablending($photo, true);
    imagesavealpha($photo, true);
    imagealphablending($frame, true);
    imagesavealpha($frame, true);

    imagecopy($photo, $frame, 0, 0, 0, 0, $w, $h);
    imagepng($photo, $newCustomPhotoName);
}



//echo $newCustomPhotoName;
copy("$newCustomPhotoName", 'media/catalog/category/custom/' . $newCustomPhotoName);
unlink($newCustomPhotoName);
//$session->setData("CustomSeatCoverImage", 'catalog/category/custom/'.$newCustomPhotoName);
die($newCustomPhotoName);

这是我今天发现的:我将此代码添加到save-custom-seats.php顶部代码将创建文件夹并将图像添加到其中

echo "$style\n\n";
echo "$top\n\n";
echo "$side\n\n";
//this works
$srcfile='http://shop.enjoymfg.com/media/catalog/category/file_5.jpg'; // image in another folder on the server
$dstfile='media/catalog/category/custom-test/test2.jpg'; // new destination as a test for writing 
mkdir(dirname($dstfile), 0755, true);
if (!copy($srcfile, $dstfile)) { // checks to see if the src copies to the new desination
    echo "failed to copy test...\n";
}

//this does not work
if (!copy("$newCustomPhotoName", 'media/catalog/category/custom-test/' . $newCustomPhotoName)) {
    echo "failed to copy $newCustomPhotoName...\n";
}

这给了我一个警告,说明图像无法复制到目录中。我会继续寻找,但如果有人可以提出更好的方法来写一些错误检查,我会很感激。我不确定如何获得有关它为什么不写入目录的更多详细信息。

我确实检查了权限,目录是可写的。

php jquery magento
1个回答
0
投票

我想看看以下内容: - 在media//catalog/category/custom/ribbed_1517529293131.png中,媒体//后面的网址有两个斜杠 - 内容类型也是text / html而不是image / png。 - 检查图像是否实际创建 - 如果是,请查看新图像是否可以使用正确的文件权限读取 - 如果图像没有创建,也检查你是否有权写文件,对不起,代码不是很清楚。

© www.soinside.com 2019 - 2024. All rights reserved.