Your path is different to the error message?
Allow PHP to write files to storage without using Storage Facade
I am attempting to save a file to public/storage/images/graphs however every time I attempt to do this I get an error.
Can't write to file "http://127.0.0.1:8000/images/graphs/test.png". Check that the process running PHP has enough permission.
Unfortunately I can't use the Storage::put() put method with this (or at least I have no clue how). Is there a way to change the filesystem permissions to allow this to happen?
@Snapey Ah, I was typing manually and missed it, but even adding storage to the path above reproduces the same error.
@Digisol So, why can't you write to the storage folder directly?
@Snapey You mean via Storage::put()? I have tried using the facade, but I'm not sure how to get the data into it properly. Another library is doing all of the back end work of prepping the image from a chart. It then gives me the Stream or Stroke options to serve up the file. Attempting to route either of them into Storage has resulted in errors.
@Digisol whatever code you are using, but pointed at the storage folder.
$graph = new Graph\PieGraph(350, 250);
$graph->title->Set("A Simple Pie Plot");
$graph->SetBox(true);
$legends = ['A (%d)','B (%d)','C (%d)','D (%d)','E (%d)',];
$data = array(40, 21, 17, 14, 23);
$p1 = new Plot\PiePlot($data);
$p1->SetLegends($legends);
$p1->ShowBorder();
$p1->SetColor('black');
$p1->SetSliceColors(array('#1E90FF', '#2E8B57', '#ADFF2F', '#DC143C', '#BA55D3'));
$graph->legend->SetPos(0.5,0.98,'center','bottom');
$graph->Add($p1);
$graph->Stroke(asset('storage/test.png'));
This is the code, I've tried pointing it to storage directly as you can see above. It results in the same permissions error.
$graph->Stroke() ?
public function Stroke($aStrokeFileName = '')
{
// If the filename is the predefined value = '_csim_special_'
// we assume that the call to stroke only needs to do enough
// to correctly generate the CSIM maps.
// We use this variable to skip things we don't strictly need
// to do to generate the image map to improve performance
// a best we can. Therefor you will see a lot of tests !$_csim in the
// code below.
$_csim = ($aStrokeFileName === _CSIM_SPECIALFILE);
// If we are called the second time (perhaps the user has called GetHTMLImageMap()
// himself then the legends have alsready been populated once in order to get the
// CSIM coordinats. Since we do not want the legends to be populated a second time
// we clear the legends
$this->legend->Clear();
// We need to know if we have stroked the plot in the
// GetCSIMareas. Otherwise the CSIM hasn't been generated
// and in the case of GetCSIM called before stroke to generate
// CSIM without storing an image to disk GetCSIM must call Stroke.
$this->iHasStroked = true;
$n = safe_count($this->plots);
if ($this->pieaa) {
if (!$_csim) {
if ($this->background_image != '') {
$this->StrokeFrameBackground();
} else {
$this->StrokeFrame();
$this->StrokeBackgroundGrad();
}
}
$w = $this->img->width;
$h = $this->img->height;
$oldimg = $this->img->img;
$this->img->CreateImgCanvas(2 * $w, 2 * $h);
$this->img->SetColor($this->margin_color);
$this->img->FilledRectangle(0, 0, 2 * $w - 1, 2 * $h - 1);
// Make all icons *2 i size since we will be scaling down the
// imahe to do the anti aliasing
$ni = safe_count($this->iIcons);
for ($i = 0; $i < $ni; ++$i) {
$this->iIcons[$i]->iScale *= 2;
if ($this->iIcons[$i]->iX > 1) {
$this->iIcons[$i]->iX *= 2;
}
if ($this->iIcons[$i]->iY > 1) {
$this->iIcons[$i]->iY *= 2;
}
}
$this->StrokeIcons();
for ($i = 0; $i < $n; ++$i) {
if ($this->plots[$i]->posx > 1) {
$this->plots[$i]->posx *= 2;
}
if ($this->plots[$i]->posy > 1) {
$this->plots[$i]->posy *= 2;
}
$this->plots[$i]->Stroke($this->img, 1);
if ($this->plots[$i]->posx > 1) {
$this->plots[$i]->posx /= 2;
}
if ($this->plots[$i]->posy > 1) {
$this->plots[$i]->posy /= 2;
}
}
$indent = $this->doframe ? ($this->frame_weight + ($this->doshadow ? $this->shadow_width : 0)) : 0;
$indent += $this->framebevel ? $this->framebeveldepth + 1 : 0;
$this->img->CopyCanvasH(
$oldimg,
$this->img->img,
$indent,
$indent,
$indent,
$indent,
$w - 2 * $indent,
$h - 2 * $indent,
2 * ($w - $indent),
2 * ($h - $indent)
);
$this->img->img = $oldimg;
$this->img->width = $w;
$this->img->height = $h;
for ($i = 0; $i < $n; ++$i) {
$this->plots[$i]->Stroke($this->img, 2); // Stroke labels
$this->plots[$i]->Legend($this);
}
} else {
if (!$_csim) {
if ($this->background_image != '') {
$this->StrokeFrameBackground();
} else {
$this->StrokeFrame();
$this->StrokeBackgroundGrad();
}
}
$this->StrokeIcons();
for ($i = 0; $i < $n; ++$i) {
$this->plots[$i]->Stroke($this->img);
$this->plots[$i]->Legend($this);
}
}
$this->legend->Stroke($this->img);
$this->footer->Stroke($this->img);
$this->StrokeTitles();
if (!$_csim) {
// Stroke texts
if ($this->texts != null) {
$n = safe_count($this->texts);
for ($i = 0; $i < $n; ++$i) {
$this->texts[$i]->Stroke($this->img);
}
}
if (_JPG_DEBUG) {
$this->DisplayCSIMAreas();
}
// Should we do any final image transformation
if ($this->iImgTrans) {
$tform = new Image\ImgTrans($this->img->img);
$this->img->img = $tform->Skew3D(
$this->iImgTransHorizon,
$this->iImgTransSkewDist,
$this->iImgTransDirection,
$this->iImgTransHighQ,
$this->iImgTransMinSize,
$this->iImgTransFillColor,
$this->iImgTransBorder
);
}
// If the filename is given as the special "__handle"
// then the image handler is returned and the image is NOT
// streamed back
if ($aStrokeFileName == _IMG_HANDLER) {
return $this->img->img;
}
// Finally stream the generated picture
$this->cache->PutAndStream(
$this->img,
$this->cache_name,
$this->inline,
$aStrokeFileName
);
}
}
What package are you using?
@Snapey JPGraph
You need to specify a path not a url
$graph->Stroke(storage_path('app/public/test.png'));
@Snapey Thanks so much, I have been toying with this for hours!
Please or to participate in this conversation.