I am working on cakephp based project
Making thumbnails using phpThumb plugin
need to create thumbnail of an external image link
phpThumb is generating thumbnail from this server
http://watermark.propspace.com
but not from this server
https://propspaceuae.s3.amazonaws.com
i am getting this error Off-server thumbnailing is not allowed
to solve this i did the following
in phpThumb.config.php file
i changed nohotlink_enabled false
$PHPTHUMB_CONFIG['nohotlink_enabled'] = false;
and added domain on nohotlink_valid_domains
$PHPTHUMB_CONFIG['nohotlink_valid_domains'] = array(#$_SERVER['HTTP_HOST'],'propspaceuae.s3.amazonaws.com');
but not worked for me
i found this solution here Link
but this is not working for me.
I got the solution by changing this line
$PHPTHUMB_CONFIG['nohotlink_enabled'] = false;
to
$PHPTHUMB_CONFIG['nohotlink_enabled'] = true;
and i added domain in phpThumb.class.php file
var $config_nohotlink_valid_domains = array('propspaceuae.s3.amazonaws.com');
And it worked for me.
Related
Hello Folks, I hope you guys are well.
Last week I am getting an issue in my Laravel Application which is regarding the S3 bucket.
Files, Images and PDF are not getting store in my S3 Bucket. The code which I have written is working fine for me for last 10 months in production environment.
Then I checked that code in my local machine which is (localhost) and that is working fine. Then I clear my Laravel Application its Cache , Views , Routes , Config. Also, checked my .env file which is same as local environment.
The last thing which I can do is check the incognito mode after clearing all the cache routes and other things. In incognito mode my files are getting uploaded for the production site but when I upload that image from the normal window its showing me the get file content error.
I am giving you the screenshots and the code which I am using let me know if you can help me with this and yes I know the problem is very strange.
My Controller Function
public function saveAboutBannerSlide(Request $request){
$banner_tile = $request->banner_title;
$banner_des = $request->banner_des;
//Getting File name form the form
$file = $request->file('banner_image');
//S3 OBJECT
$s3 = Storage::disk('s3');
$new = uniqid() . "_banner";
//Uploading With the New Name
$upload_path = 'uploads/manage-cms/aboutus-images/' . $new;
//Put File in S3 Bucket
$s3->put($upload_path, file_get_contents($file));
//Getting URL OF THE Image
$up_img = $s3->url($upload_path);
}
Error image while uploading image
Well, I've uploaded an app to Heroku, and I've discovered that I can't upload files to it. Then I started to use Dropbox as storage option, and I've done a few tests, of send and retrieve link, and all worked fine.
Now, the problem is to use the uploadFile() method on DropboxAdapter. He accepts an resource as the file, and I did'nt work well. I've done a few tests, and still no way. Here is what I am doing, if anyone could me point a solution, or a direction to this problem, please. :)
Here is my actual code for the update user (Update the user image, and get the link to the file).
$input = $_FILES['picture'];
$inputName = $input['name'];
$image = imagecreatefromstring(file_get_contents($_FILES['picture']['tmp_name']));
Storage::disk('dropbox')->putStream('/avatars/' . $inputName, $image);
// $data = Storage::disk('dropbox')->getLink('/avatars/' . $inputName);
return dd($image);
In some tests, using fopen() into a file on the disk, and doing the same process, I've noticed this:
This is when I've used fopen() on a file stored on the public folder
http://i.imgur.com/07ZiZD5.png
And this, when i've die(var_dump()) the $image that I've tried to create. (Which is a suggestion from this two links: PHP temporary file upload not valid Image resource, Dropbox uploading within script.
http://i.imgur.com/pSv6l1k.png
Any Idea?
Try a simple fopen on the uploaded file:
$image = fopen($_FILES['picture']['tmp_name'], 'r');
https://www.php.net/manual/en/function.fopen.php
You don't need an image stream but just a filestream, which fopen provides.
I am using Codeigniter's image_lib library to resize my images, it is working fine but it renames the image as "original_name_thumb.ext". I dont want it to rename it by adding _thumb. I am saving them in new folders. So rename is not required.
just set thumb_marker = "";
$config["thumb_marker"] = "";
while setting config for image library and it should work fine. See docs
I am doing products import php script for prestashop 1.3.1 and I have one problem. I have URL of picture, but i dont know hoe to use it and make different images (thumbnails it is called I think).
If I have picture http://www.nordix.cz/img/p/824-2268.jpg what I must write in PHP to make thubnails?
Thank you so much for tips!
To process an image (create thumbs) first you have to copy it to a local directory. You can't do any processing on an image which is on another server or url. So here is how i did it in one of my PS project.
1) First check if the image exists or not. You can do it by using fopen in read mode, if it returns true, then the file exists. It is a good practice to do it because it will avoid unnecessary calls to the remote server.
$imageUrl = "http://www.nordix.cz/img/p/824-2268.jpg";
#fopen($imageUrl, "r");
2) Now you have the image as the fopen returned true, you need to copy the image to the PS temp directory as below
$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS');
copy($imageUrl , $tmpName);
after the copy function downloads the image to PS temp directory, then you can process that image as you want. Remember that you have to make all processing on $tempName, as it is the file now. $tempName is like $_FILES['imageFieldName']['tmp_name'].
Thank you
Prestashop provides a set of function to process images. I've never worked on 1.3 but in 1.4 they are located in /images.inc.php (they made a class in 1.5). Take a look at this file and you will find all the function you will need, especially imageResize()
I am using the FPDF library for generating PDF files by PHP. This library is working fine with plain text(i.e PDF files are generating for any text), but this is giving me an error of FPDF error: Missing or incorrect image file:{MY_FILE_PATH} while trying to add an image to my PDF page. Accessed that file path through the browser, then the corresponding image is appearing fine.
My code is:
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 16);
$pdf->Write(10, 'Example image');
$image_path = MY_FILE_PATH; // This variable contains my actual file path
$pdf->Image($image_path, 10, 10, 350, 450);
$pdf->Output();
This code is working perfectly in my localhost and generating the corresponding PDF files even with the images also, but this is not working after moving to the server.
I have tried with these possibilities like:
With absolute and relative paths for the image.
Tried with a local image placed in the same folder.
All image formats like jpg, png and gif also.
Checked the permissions for the image and corresponding folders also.
None of these cases are working for me, stuck with this problem, can anyone help me to slove this issue.
Thanks!
Siva ...
After a long struggle finally I found the reason for this issue which I've already discussed here.
Mainly this problem is due to the 'allow_url_fopen' setting which is not enabled for my server, I've solved this issue by using the CURL. I'm giving the step by step procedure to solve this issue because this may useful for somebody like me to avoid wastage of time(for finding the solution).
1. Create a temporary file in the local system with write permission.
Ex: $fp = #fopen($local_file_path, 'x');
fclose($fp);
2. Get the remote location file contents using CURL and write that to local file
which is created in the previous step.
Ex: $curl = new CurlWrapper($remote_file_path);
$curl->copyToFile($local_file_path);
3. Now send this local file path to FPDF function(image) then the corresponding
PDF will get generate for the file without any issues.
I think this is one method to solve this issue, if anybody knows some other ways then you can post them here so that this question may be useful for somebody.
just add:
allow_url_fopen = ON
on php.ini (create new if not exists) solves the problem.
http://www.solo-technology.com/blog/2010/04/07/quick-fix-for-url-file-access-is-disabled-issues/
anyone can use this code for solve. may be it will work. because sometime some case may be different. in my case i was getting same issue but after use it. i fixed my issue..
$pdf->Image($image_path, 10, 10, 350, 450 ,'');
try to give empty string to 6 parameter of $pdf->Image() function or you can give file extension like ( PNG or JPG). in my case empty string '' was working. because i was cropping image so that image going some time wrong. so after do that my problem gone fixed and i tested with different images.