CakePHP saving thumbnail image error (unable to open) - cakephp

I am using WebTechNick's file upload plugin to save images on my CakePHP site. That part is working perfectly. I am working in my projects_controller in the add action I loop through the uploaded files and attempt to create and save thumbnails. The thumbnail creation goes well, but I get this error when trying to save the images to the thumbnail directory.
Unable to open 'files/project_images/thumbs' for writing: Is a directory
my files, project_images, and thumbs are all chmoded to 777 so I dont see why I am getting an "unable to open" error. My full code is below.
for($i=0; $i<=2; $i++){
$path = 'files/';
$imageName = $this->Project->Image->read('name', $imageStartingId);
$fullPath = $path . $imageName['Image']['name'];
list($width, $height) = getImageSize($fullPath);
$ratio = $width/$height;
$thumbnailHeight = $thumbnailWidth/$ratio;
//resample
$imageThumb = imagecreatetruecolor($thumbnailWidth, $thumbnailHeight);
$image = imagecreatefromjpeg($fullPath);
imagecopyresampled($imageThumb, $image, 0,0,0,0, $thumbnailWidth, $thumbnailHeight, $width, $height);
imagejpeg($imageThumb, 'files/project_images/thumbs', 100);
$imageStartingId--;
}
any help is much appreciated. Thanks!

You need to give imagejpeg() a filename, and you've given it only the path, as the error message says. Change it to
imagejpeg($imageThumb, 'files/project_images/thumbs/'.$imageName['Image']['name'], 100);
or whatever you want the filename to be.

Related

Block direct downloads using Symfony

I want block the direct access to some of public files from my directory. For example, I have the file image.png and I have to fill a captcha to download that file, if I fail the captcha I don't want that the user could access the file. Is there any way to do that in Symfony?
First of all, create an .htaccess file inside the image directory to prevent the direct access of files inside the directory.
Deny from All
Now, give customised path, through controller to download the file, where you can easily integrate a captcha by using some bundle like Gregwar's CaptchaBundle.
On successful captcha validation, download the file through Response.
$filename = __DIR__ . "../path_to_file/image.png";
// Generate response
$response = new Response();
// Set headers
$response->headers->set('Cache-Control', 'private');
$response->headers->set('Content-type', mime_content_type($filename));
$response->headers->set('Content-Disposition', 'attachment; filename="' . basename($filename) . '";');
$response->headers->set('Content-length', filesize($filename));
// Send headers before outputting anything
$response->sendHeaders();
$response->setContent(file_get_contents($filename));
Note : Code not tested!
Hope this helps!

Manual custom script partially working.

I need to export my target path and request path url's of my products and categories.
custom code :
<?php
require_once('app/Mage.php');
Mage::app();
$data=Mage::getModel('core/url_rewrite')->getCollection();
$fp = fopen('exports.csv', 'w+');
$csvHeader = array('request_psth',"target_path");
fputcsv( $fp, $csvHeader,",");
foreach($data as $row)
{
fputcsv($fp, array($row->getData('request_path'),$row->getData('target_path')), ",");
}
fclose($fp);
?>
Its working in my localhost, and i get export file, when i try to applied on hosting site, its not working.
i have post my code via ftp, like
screen shot
You should upload the product to the magento root directory, then only it will work as it is including Mage.php.
Also make sure your file has enough permission to execute. Once you uploaded the file using ftp, change the permission by
Right click on the file, select File permissions type 755 in the text field

CakePdf won't generate pdf file inside a folder

Im using cakepdf for generating pdf files using wkhtmltopdf and it works, the issue is when i wanted to create pdf files inside a folder it shows me this exception :
System error <pre>Exit with code 1 due to network error: ContentNotFoundError </pre>
Here's the code Im using for generating the pdf file :
$CakePdf = new CakePdf();
$CakePdf->template('mynote','default');
//get the pdf string returned
$pdf = $CakePdf->output();
//or write it to file directly
$pdf = $CakePdf->write(APP . 'webroot'. DS .'files' . DS . 'mynote.pdf');
and for the pdf template i used mynote.ctp that only contains this code inside pdf folder
<div>Hello</div>
After some hustle i disbaled this error by commenting the code inside output functions but still i can't get the style and the images,like i use to.
Thanks in advance.

Correct way in CakePHP 1.3 to create zip file and download without leaving view

I just upgraded from cakephp 1.1 to 1.3. I have everything on the site updated and working great, except for creating and downloading zip files.
Here is the code in my accounts_controller.php:
function zip() {
$this->checkSession();
$this->checkUpgradedAccount();
$files = array();
$this->layout="zip";
/*
code where I locate the files to zip, combine them, etc
*/
$tmp_file = "/home/[userdirectory]/tmp/".md5(mktime()).".zip"; //directory name edited
$command = "/usr/bin/zip -j $tmp_file ".implode(" ",$zip_files);
exec($command);
foreach($zip_files as $zf) {
unlink($zf);
}
$file_path = $tmp_file;
$this->set("path",$file_path);
$this->render();
}
When I call this action, however, I get an error:
Error: The requested address '/accounts/zip' was not found on this
server.
It worked just like this in version 1.1. I'm assuming something has changed, but I'm not sure what, and was unable to find anything pertinent in the documentation.
The zip.ctp view file does exists, but it has nothing in it other than: <?php ?>
I suspect something is different with layouts. There is NO "zip.ctp" in the /layouts directory. However, I have changed that line to $this->layout('default'); and it renders a blank page with NO ERROR, but also with no download.
Please direct me on the proper way to download my zip file in cake 1.3. Thanks in advance.
You have two different problems here. That error you're getting is because you don't have a zip layout file. As for your problem with getting the zip file, you should be using the media view class - http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Views.html#media-views

get uploaded file details in next step of a multistep form

I am new to module development .
I am creating a multi step form .
on the first step i am uploading a image file .
In the next step i have some form fields and want to display the image and other details of the image .
I have successfully uploaded the image file but unable to get the file details in the form .
I have read the druapl file api but didnot find any solution .
Thanks and Regards
Parth
Something like this should do it:
$fid = $form_state['values']['file_element_name'];
$file = file_load($fid);

Resources