saving image from HTTP_RAW_POST_DATA does not work in MAMP - http-post

I'm using the following to upload an image from post data. it works on my server using php version: 5.2.16
When I try running the exact same script on my local server using MAMp and PHP Version 5.2.17
the file is not created.
if (isset($HTTP_RAW_POST_DATA))
{
// Get the data
$imageData=$HTTP_RAW_POST_DATA;
// Remove the headers (data:,) part.
// A real application should use them according to needs such as to check image type
$filteredData=substr($imageData, strpos($imageData, ",")+1);
// Need to decode before saving since the data we received is already base64 encoded
$unencodedData=base64_decode($filteredData);
echo "unencodedData: ".$unencodedData;
$key = microtime();
$key = md5($key);
// Save file.
$fp = fopen( '../../../uploadedImages/original/' . $key . '.jpg', 'wb' );
fwrite( $fp, $unencodedData);
fclose( $fp );
}
it looks like the post data does exist if I look at it in firebug. Any ideas why this isn't working in mamp?

Some things to try:
Check to make sure you are getting the raw data when the script is running on MAMP
Check the permissions of the directory it is trying to write to and make sure you have write access to it and apache has write access to it.
I had issues running some php modules on MAMP so I switched to using versions I installed using MacPorts. It gave me more control of extra extension I wanted to install and I got the latest versions of apache, php, and the php extensions.

Related

Laravel 8.55 and queue behavior using S3 file upload

I inherited some Laravel code (currently running version 8.55) and there is a job that is initiated by uploading a CSV file via a web page.
That CSV file uploaded to an S3 bucket, processed (using the Laravel-Excel), causing updates to database entries, an email is sent reporting job completion and then the CSV file is deleted from S3.
My development environment is Windows11 (PhpStorm) using MySql and 'php artisan serve' is the webserver that I use.
The queued job works as expected in my local environment. When attempted in production (hosted on heroku), the file is successfully uploaded to the S3 bucket I'm using and then the following error results (reported in Bugsnag) and the job fails (adding an entry to the failed_jobs table):
Illuminate\Contracts\Filesystem\FileNotFoundExceptionMaatwebsite\Excel\Jobs\ReadChunk
File not found at path: laravel-excel-3svOWxojWikYEuWZuBBBHlbXl6WpK7Xb.csv
This is an excerpt of the code in the upload script that initiates the job:
$file = $request->file('filename');
$f_ori_name = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
$file_name = Str::random(40).'.'.$extension;
$tmp_path = Storage::disk('s3_temp')->put($file_name, file_get_contents($file->getRealPath()));
$path = Storage::disk('s3_temp')->path($file_name);
$var = (new MembersImport($currentPerson, $import_detail))->queue($path, 's3_temp')
->chain([
new ImportDetailsUpdateJob($import_detail),
new NotifyUserOfCompletedImport($currentPerson, $import_detail),
function () use ($path) {
Storage::disk('s3_temp')->delete($path);
}
])->onConnection('database')
->onQueue('default');
I'm at a loss given that this works completely locally.
The answer, as pointed out by #matiaslauriti, was incorrect AWS keys in one of the environments that was processing the production queue.

Command (insert) is not available for driver (Gd)

Hello Im working with Image Intervention. Project working very well from local server.
My remote server Digitalocean droplet and Lamp Ubuntu 14.04 installed. Im sure all necessary modules installed and active.
GD Version => 2.1.1-dev
imagick module version => 3.1.2
PHP Version 5.5.9-1ubuntu4.21
Image::make('uploads/products/'.$filename)->fit(440, 585)->insert('uploads/watermark.png','center',0,0)->save('uploads/products/'.$filename, 100);
if ->insert function bypass my codes working on droplet. but when add to ->insert to code throwing error message.
Laravel 5.2 throw this error message: Command (insert) is not available for driver (Gd) Im trying all of my mind. how to fix this problem. I lost a one day :(
setlocale(LC_ALL, 'en_GB.UTF-8');
$file = $request->file('file');
list($filename, $extension) = explode(".", $file->getClientOriginalName());
$filename = strtolower(str_slug(uniqid().'-'.$filename).'.'.$extension);
$fileSave = $file->move('uploads/post',$filename);
Image::make('uploads/post/'.$filename)->fit(440, 585)->insert('uploads/watermark.png','center',0,0)->save('uploads/post/'.$filename, 60);
setlocale(LC_ALL, 'tr_TR.UTF-8');
I solved my problem.
I before using Turkish locale settings on server. When I set to Turkish locale settings on any Ubuntu version. All small "i" characters changing big "İ" characters. you know right classnames on Laravel Framework. Every class names starting big characters. We dont need "İ" character working with developing codes.
This problem stole 3 days from my life. I am 12 times rebuilding to server. Im happy now !

Deprecated: mysql_connect() message and Warnings occur in step 3 of the opencart configuration setup after we enter the details and hit continue

We need help trying to upload our opencart templatemonster.com template correctly on godaddy but we are not clear on how to do that.
FYI our public_html/system/database folder contains a mysqli.php file as well.
We made sure to upload the template via fullpackage (The name of the file is themeXXX(full).zip, where XXX is your theme number) to the public_html folder.
Extracted the zip files in the public_html folder.
Performed the installation using the installation manager .
At step 3 configuration we were prompted to input our database access details and made sure the database was empty. (GoDaddy told us to use the localhost)
After hitting continue:
The deprecated: mysql_connect() message and Warnings occur in step 3 of the opencart configuration setup after we enter the details and hit continue.
Where ‘store’ is the new directory name. Where ‘user’ is your server
account address. Where ‘yourdomainname.co.uk’ is the web domain of
your new website:
(DUMMY LINK FOR DEMONSTRATION PURPOSES) http://www.yourdomainname.co.uk/install/index.php?route=step_3
Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/user /public_html/system/database/mysql.php on line 6
Lines 5-16:
public function __construct($hostname, $username, $password, $database) {
if (!$this->link = mysql_connect($hostname, $username, $password)) {
trigger_error('Error: Could not make a database link using ' . $username . '#' . $hostname);
}
if (!mysql_select_db($database, $this->link)) {
trigger_error('Error: Could not connect to database ' . $database);
}
Errors:
Warning: Cannot modify header information - headers already sent by (output started at /home/user/public_html/system/database/mysql.php:6) in /home/user/public_html/system/engine/controller.php on line 28
Warning: Cannot modify header information - headers already sent by (output started at /home/user/public_html/system/database/mysql.php:6) in /home/user/public_html/system/engine/controller.php on line 29
Lines 27-31
protected function redirect($url, $status = 302) {
header('Status: ' . $status);
header('Location: ' . str_replace(array('&', "\n", "\r"), array('&', '', ''), $url));
exit();
}
Template Features
OpenCart Compatibility: 1.5.6.x
OpenCart Engine: 1.5.6.4
(Trimmed)
Sources Available
PSD PNG PHP TPL JS
Hosting Requirements
Web Server (preferably Apache)
PHP (at least 5.2)
MySQL
Curl
Fsock
OpenCart Templates Help Center
Software Required
Adobe Photoshop CS+
For uncompressing a template ZIP package: WinZip 9+ (Windows);
Stuffit Expander 10+ (Mac)
Apache Server
PHP v. 5 or higher
MySQL 4.1.14 or later
OpenCart 1.5.6.4
Sublime Text2 or later, Notepad++ or any php-editor
A commenter stated
mysql_ calls will work on this server but are causing deprecation
notices. A quick fix would be to turn off warnings in your php.ini
file, in your error_reporting value. Or you could try turning off
display errors, set display_errors to 0.
I like the comment but could someone provide a slightly more comprehensive explanation or visual resource to this suggestion? Such as articulating a little further how to proceed? Should I download the file through GoDaddys public FTP or should I use FileZilla FTP client (does it matter), make a copy, make the proper changes then re-upload?
I like the possible solution but I am curious to know if these are the only ones.
UPDATE
I just changed display_errors = 1; to display_errors = 0;
saved the file (I edited the file withing GoDaddy's text editor)
re-input our database access details
hit continue on step 3 configuration and got the same error.
php.ini
magic_quotes_gpc = Off;
register_globals = Off;
default_charset = UTF-8;
memory_limit = 64M;
max_execution_time = 36000;
upload_max_filesize = 999M;
safe_mode = Off;
mysql.connect_timeout = 20;
session.use_only_cookies = On;
session.use_trans_sid = Off;
session.cookie_httponly = On;
session.gc_maxlifetime = 172800;
allow_url_fopen = on;
;display_errors = 0;
;error_reporting = E_ALL;
???
I have a similar experience! You don't need to enable these extensions the PHP Version needs to be update:
Sign into GoDaddy
Go to My Products under your sign in name at the top right.
Go to Web Hosting and click the Manage button.
Click manage again.
Scroll to the Software header and click "Select PHP Version"
Then change to an earlier version, in which this extension is not deprecated.
Let me know how that works for you.

Fatal error: Class 'Category' not found after PHP version upgrade

I use CodeIgniter 2.1 and my production server was updated to PHP 5.4.3-1, and the pages that uses phpactiverecord don´t show nothing and don't show any error.
In my test servers with 5.3.6 works fine.
I use the nightly build version of May 2012. I try with the older versions and stable version.
Php-activerecord don´t work fine with php 5.4.3?
EDIT: I found that my new server doesn´t have displays_errors = ON. After activate it, I see the error:
Fatal error: Class 'Category' not found in /srv/www/framework/application/controllers/categories.php on line 26
at line 26:
$data["categories"] = Category::findby($parent_id);
categories.php exists in /srv/www/framework/application/controllers/ and this works fine on PHP 5.3.6.
I need to call something more or call at a different way?
I found the solution.
This solution is for php-activerecord through the latest SPARKS version.
Debugging the autoload_function, I´ve seen that the model file was loaded with the first letter capitalized, only in PHP 5.4.3, not in 5.3.x, and the file wash´t loaded.
Find the ActiveRecord.php at
yourfolder/sparks/php-activerecord/0.0.0.2/vendor/php-activerecord
Search the function:
activerecord_autoload($class_name)
Line 49 change:
$file = $root.DS.$file_name;
for
$file = $root.DS.strtolower($file_name);
And now it works!
p.d. I have found another strange case with PHP 5.4.3 before solve this. The function parse_url() returns false if your database password has a '/' on the string. Because of this, php-activerecord could not connect to the database in the file yourfolder/sparks/php-activerecord/0.0.0.2/vendor/php-activerecord/lib/connection.php at function: file parse_connection_url().
On PHP 5.3 returns the correct array.

how to install gmagick extension of php on windows vista

gmagick is newer version of imagemagick with more set of features it is less resource intensive and fast but the problem is there is very few discussion about this wonderful tool on web i recently came across this on
http://devzone.zend.com/1559/manipulating-images-with-php-and-graphicsmagick/
but i could not install it on windows machines cos phpize did not work so i tried some other way and some how managed to get on phpinfo page but i could not make it work further i colud not even open a single image with gmagick
this is code i used
<?php
$path="gallery/img1.jpg";
// initialize object
$image = new Gmagick($path);
echo $image;
// read image file
$file = 'gallery/img1.jpg';
$image->readImage($file);
echo '<img src="' . $file . '" width="200" height="150" /> <br/>';
?>
i used this code to instanstiate gmagick class and open image but i am geeting very big error as follows
Fatal error: Uncaught exception 'GmagickException' with message 'Unable to open file (gallery/img1.jpg)' in C:\xampp\htdocs\junk\imgproc\imgproc1.php:4 Stack trace: #0 C:\xampp\htdocs\junk\imgproc\imgproc1.php(4): Gmagick->__construct('gallery/img1.jp...') #1 {main} thrown in C:\xampp\htdocs\junk\imgproc\imgproc1.php on line 4
A) To answer the question in your headline (that might lead other readers here):
Windows builds of the GraphicsMagick extension for PHP can be obtained here:
http://valokuva.org/builds/
Check whether you need the thread-safe version or not by looking at a phpinfo(); output of your webserver. Look for the entry Thread Safety. In the entry PHP Extension Build you should also find the VC version that you need, e.g. API20090626,TS,VC9 for VC9.
Download the latest build that matches your conditions, put it into your PHP/ext directory and add it to your php.ini like this:
extension=php_gmagick_ts.dll
Remember to correct the name of the dll if you use the non-TS version.
Restart Apache and check phpinfo();. There should be a gmagick block now..
B) To correct the problem with your code:
The Gmagick constructor does not expect a path as a parameter, but a full image filename (may include a path). Most often it is better to leave it empty and provide the file in the readImage() call.
Try a full $path (starting at root) and use it in readImage() and writeImage():
Here is an example of a working piece of code:
<?php
// assuming this is the path to your code and to your image files
$path = 'C:\xampp\htdocs\junk\imgproc\';
$image = new Gmagick();
$file = 'img1.jpg';
$image->readImage($path.$file);
// The rest of your code does not make any use of the GM instance,
// so I add something functional here: create a grayscale version and show it
$fileOut= 'img1_GRAY.jpg';
$image->setImageType(Gmagick::IMGTYPE_GRAYSCALE);
$image->writeImage($path.$fileOut);
$image->destroy();
echo "<img src='$fileOut' >";
?>
It should show a grayscale version of your image file.

Resources