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);
Related
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!
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
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.
I use CakePHP-Upload plugin, now need to use the upload without form, following this example: Programmatic File Retrieval without a Form
All my upload are stored in the associated model, called the Attachment.
So when I save the article, at the same time save the images in Attachmen model.
Plugin documentation suggests something like this:
<?php
$this->Article->set(array('file' => $image_path)); // ?????
$this->Article->save();
?>
I have a larger collection of images on the server, previously uploaded via the Joomla CMS, now I have a migration of data to a custom CMS built on CakePHP framework. I need to take all these pictures and upload again, through this plugin.
How to properly use this plugin for my needs, I try to put the path to a local picture, but uploading is not working ???
EDIT
$image_path = WWW_ROOT . 'img' . DS . 'attachment' . DS . '59'.DS.'hpim4799.jpg';
debug($image_path);
'C:\xampp\htdocs\portal\webroot\img\attachment\59\hpim4799.jpg'
Do not save the record and not create new images.
Note, uploading through HTML form works well, I use windows 7 and xampp server.
EDIT 2 / Solution
Image path must be valid url like 'http://localhost/portal/img/attachment/59/hpim4799.jpg'
$image_path = Router::url('/', true) . 'img/attachment/59/hpim4799.jpg';
Thank you.
Can you tell me what the content of the variable $image_url is? The doucmentation says you can add a file via the form, or you can do it programmatically. If you do that, use the $image_url as path to the image. If you got an associated model like Attachment you shoud use:
<?php
$this->Article->set(array('Attachment.file' => $image_path)); // path + file to file
$this->Article->save();
?>
After hours of searching for solutions and detailed inspection of the Behavior code I finally found it.
Because Behavior uses php FILTER_VALIDATE_URL Filter, path must be a valid URL. Here is an example:
<?php
$image_path = Router::url('/', true) . 'img/attachment/59/hpim4799.jpg';
// return http://localhost/portal/img/attachment/59/hpim4799.jpg
$this->Article->Attachment->set(array('file' => $image_path));
$this->Article->Attachment->save();
?>
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.