Laravel Lumen image validation is not working - php

I'm validating a request as an image, but crashes saying:
"Unable to guess the MIME type as no guessers are available (have you
enable the php_fileinfo extension?)".
In php.ini I don't have a extension=php_fileinfo, but I do have a extension=fileinfo uncommented line (I see Lumen put this and other dependencies without the 'php_'). I also try adding extension=php_fileinfo, but when I restart Apache from XAMPP it crashes because it doesn't find that dependency. What should I do?
The code:
function updateProfilePicture(Request $request) {
$this->validate($request, [
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048'
]);
//...
The php.ini section where fileinfo dependency is:
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
; If you wish to have an extension loaded automatically, use the following
; syntax:
;
; extension=modulename
;
; For example:
;
; extension=mysqli
;
; When the extension library to load is not located in the default extension
; directory, You may specify an absolute path to the library file:
;
; extension=/path/to/extension/mysqli.so
;
; Note : The syntax used in previous PHP versions ('extension=<ext>.so' and
; 'extension='php_<ext>.dll') is supported for legacy reasons and may be
; deprecated in a future PHP major version. So, when it is possible, please
; move to the new ('extension=<ext>) syntax.
;
; Notes for Windows environments :
;
; - Many DLL files are located in the extensions/ (PHP 4) or ext/ (PHP 5+)
; extension folders as well as the separate PECL DLL download (PHP 5+).
; Be sure to appropriately set the extension_dir directive.
;
extension=bz2
extension=curl
extension=fileinfo
extension=gd2
extension=gettext
Maybe is it related to that disclaimer about how to set the dependencies directives? (I'm not sure because extension=fileinfo was already in the file as a default)
I'm using windows 10 and I found the file in C:\xampp\php\ext\php_fileinfo.dll

I found the problem. I had another php.ini file with the commented line ;extension=fileinfo in C:\php\php.ini (the one I was opening was in C:\xampp\php\php.ini). Now I restarted Apache and it's working!

Related

Cannot create temporary file in unknown PHP upload

I'm building a desktop app with PHP desktop, I'm using Angular on front and Laravel at back, I'm trying a series of file uploads non of which seem to work on the clients PC but work fine on mine. He gets the error in his console - cannot create temporary file in unknown on line 0. My front-end for upload is
public formdata = new FormData()
setFile(element){
let file = element.target.files[0];
let name = element.target.id;
this.formdata.append(name,file);
}
createTraining(data){
this.formdata.append("data",JSON.stringify(data))
let url = this.$api.base()+"/training/new";
this.$http.post(url,this.formdata).subscribe((rez:any)=>{
console.log(rez);
if(rez.state){
this.$modal.dismiss()
}
})
}
My back-end is
if(#$request->file("tsd_file")){
$training->tsd_file = #$request->file("tsd_file")->store("public");
}
if(#$request->file("sc_file")){
$training->sc_file = #$request->file("sc_file")->store("public");
}
if(#$request->file("ta_file")){
$training->ta_file = #$request->file("ta_file")->store("public");
}
if(#$request->file("tka_file")){
$training->tka_file = #$request->file("tka_file")->store("public");
}
if(#$request->file("dte_file")){
$training->dte_file = #$request->file("dte_file")->store("public");
}
if(#$request->file("ete_file")){
$training->ete_file = #$request->file("ete_file")->store("public");
}
Although I hardly believe the above matter. In my local system, PHP's sys_get_temp_dir() function returns "C:\Users\noble\AppData\Local\Temp".
But on the clients pc, his system tmp dir is C://windows/temp. I wonder if that could be a contributing factor, I would appreciate some help in finding ways to resolve this
my php.ini in the root of PHP desktop is
; Extensions
extension_dir = "ext/"
extension=php_curl.dll
extension=php_gd2.dll
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_openssl.dll
extension=php_pdo_mysql.dll
extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
extension=php_pgsql.dll
extension=php_sqlite3.dll
extension=php_com_dotnet.dll
; Date
date.timezone=Europe/Berlin
; Errors
error_reporting=E_ALL
display_errors=On
display_startup_errors=On
log_errors=Off
report_memleaks=On
report_zend_debug=On
; General
short_open_tag=On
ignore_user_abort=Off
implicit_flush=Off
output_buffering=0
default_charset = "UTF-8"
; Execution time
max_execution_time=30
extension=php_fileinfo.dll
; Memory
memory_limit=128M
; File uploads
; "post_max_size" must be equal or bigger than "upload_max_filesize"
max_file_uploads=20
upload_max_filesize=20048M
post_max_size=2049M
; Smtp server is not included with phpdesktop
SMTP=127.0.0.1
smtp_port=25
Turns out all I needed to do was have the clients enable write permission and access to the windows temp folder. All works well now

PHP: Fatal error: Class 'SoapClient' not found

First of all, I've read this question (Fatal error: Class 'SoapClient' not found) and have everything done the answer says. But still experience an issue.
I also found similar issue here (https://bugs.php.net/bug.php?id=64445) but it is not solved there too.
I'm trying to set up a PHP + Apache environment on Win 7 64.
PHP: php-5.5.17-Win32-VC11-x86. Thread safe.
Apache: httpd-2.4.10-win32-VC11
So, here is my C:\PHP\php.ini for SOAP. Everything is set correctly:
extension=php_soap.dll
; Directory in which the loadable extensions (modules) reside.
; On windows:
extension_dir = "C:/PHP/ext"
[soap]
; Enables or disables WSDL caching feature.
; http://php.net/soap.wsdl-cache-enabled
soap.wsdl_cache_enabled=1
; Sets the directory name where SOAP extension will put cache files.
; http://php.net/soap.wsdl-cache-dir
soap.wsdl_cache_dir="/tmp"
; (time to live) Sets the number of second while cached file will be used
; instead of original one.
; http://php.net/soap.wsdl-cache-ttl
soap.wsdl_cache_ttl=86400
; Sets the size of the cache limit. (Max. number of WSDL files to cache)
soap.wsdl_cache_limit = 5
In C:/PHP/ext folder I have php_soap.dll file, C:\PHP\ext\php_soap.dll.
But my phpinfo(); returns ONLY this about SOAP:
I DO NOT have these settings shown:
And I get error:
Fatal error: Class 'SoapClient' not found in C:\Apache24\htdocs\myApp\src\Em\Bundle\PlatformBundle\Services\MyAppService.php on line 46
What did I miss? How to solve it?
This is very easy.
You work with Symfony2 i think and you use namespaces. This function is in the Root-Namespace.
use:
\SoapClient()
Otherwise you are in the namespace and they can't find the class.
You have the same Problem with the Exception class for example.
If you are on linux and you are missing the soap extension, like I was and you have already enabled it in php.ini then try
apt-get install php-soap
service apache2 restart
I had the same issue in a custom module Drupal 8.
It uses Symfony2 so just add this in controller :
use SoapClient;
in PHP/7.4.11 Server
In XAMPP Control Panel
Stop Apache Server
Click on Config next to Apache
From dropdown select PHP (php.ini)
Ctrl+F to find ;extension=soap and remove ; from the line.
Ctrl+S to save the file.
Start Apache again.
this steps solved my problem.
Try config the extension using the path:
extension=ext/php_soap.dll
In phpinfo() you can see this important lines:
Configuration File (php.ini) Path C:\WINDOWS
Loaded Configuration File C:\Apache24\bin\php.ini
But you can change the ini folder if desire in httpd.conf:
# configure the path to php.ini
#PHPIniDir "C:/php"
BUT SEE what extension dir are you using:
extension_dir C:\php
In the "Core" section. This can be configured too.

Failed to connect mysql in centos 6.5

I'm using php-mysql-apache in centos 6.5 system all requirements are exists, i think i can publish my html files in localhost but when i try to connect to mysql in php script. It doesn't appear and it shows mysql connection error.
# rpm -qa |grep php
php-pdo-5.3.3-26.el6.x86_64
php-common-5.3.3-26.el6.x86_64
php-5.3.3-26.el6.x86_64
php-mysql-5.3.3-26.el6.x86_64
php-cli-5.3.3-26.el6.x86_64
php-ldap-5.3.3-26.el6.x86_64
# rpm -qa |grep mysql
mysql-libs-5.1.71-1.el6.x86_64
mysql-community-release-el6-5.noarch
mysql-5.1.71-1.el6.x86_64
mysql-server-5.1.71-1.el6.x86_64
php-mysql-5.3.3-26.el6.x86_64
I also checked my mysql password and username are correct i try to connect as below :
$connect= mysql_connect("localhost","root","password");
if(!$connect){
echo "Failed to connect to MySQL " ;
}
Also "dynamic extensions" part of php.ini file as below :
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
; If you wish to have an extension loaded automatically, use the following
; syntax:
;
; extension=modulename.extension
;
; For example
;
; extension=msql.so
;
; ... or with a path:
;
; extension=/path/to/extension/msql.so
;
; If you only provide the name of the extension, PHP will look for it in its
; default extension directory.
extension=mysql.so
extension=mysqli.so
;;;
; Note: packaged extension modules are now loaded via the .ini files
; found in the directory /etc/php.d; these are loaded by default.
;;;;
I added this lines by hand;
extension=mysql.so
extension=mysqli.so
So where is my fault can do you have idea for run my php script in localhost?
Don't use mysql_connect as it is deprecated, use MySQLi or PDO to connect – it's really a pain, but check your Apache error log or enable PHP to show all errors in your scripts and it may help.

PHP : The specified procedure could not be found. in Unknown on line 0

I recently got stuck on this php error I am receiving :
PHP Warning: PHP Startup: Unable to load dynamic library 'c:\PHP\php_soap.dll' - The specified procedure could not be found. in Unknown on line 0
I have declared the dll in both my ini files. I'm running windows 7 and the site is hosted on iis using a MSSQL Database. I'm using PHP 5.4.1 (Company Policy)
My ini file for the changes :
; Directory in which the loadable extensions (modules) reside.
extension_dir = "c:\PHP"
extension=php_soap.dll
[soap]
; Enables or disables WSDL caching feature.
soap.wsdl_cache_enabled = 0
; Sets the directory name where SOAP extension will put cache files.
soap.wsdl_cache_dir="/tmp"
; (time to live) Sets the number of second while cached file will be used
; instead of original one.
soap.wsdl_cache_ttl=86400
Please help, I've tried everything. Even re-installing.
Thank you.
Are you sure php_soap.dll is in the folder c:\PHP\? If not, you need to adjust the extension_dir config setting in php.ini to the proper extension folder.

How to enable mysqli on XAMPP?

By seeing suggestions throughout the Internet I tried to convert all my queries to mysqli.
But mysqli is not working in my XAMPP. I checked my PHP folder and there is a php_mysqli.dll file... still it doesn't work
Have you declare it to php.ini to load it? If no, try find this in php.ini and add php_mysqli.dll
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
; If you wish to have an extension loaded automatically, use the following
; syntax:
;
; extension=modulename.extension
;
; For example, on Windows:
;
; extension=msql.dll
;
; ... or under UNIX:
;
; extension=msql.so
;
; ... or with a path:
;
; extension=/path/to/extension/msql.so
;
; If you only provide the name of the extension, PHP will look for it in its
; default extension directory.
;
; Windows Extensions
; Note that ODBC support is built in, so no dll is needed for it.
; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)
; extension folders as well as the separate PECL DLL download (PHP 5).
; Be sure to appropriately set the extension_dir directive.
extension= php_mysqli.dll
Goto the directory phpMyAdmin, find there is a file with name config.inc.php, open the file and find a line there as:
$cfg['Servers'][$i]['extension'] = 'mysql';
just change mysql to mysqli.
Another thing that might be blocking the msqli dll from loading could be user right issues on your local webserver, make sure the \User can read the ext folder, that was what worked for me
I think you should use XAMPP 1.8.3-1, XAMPP 1.8.2-2, XAMPP 1.8.1.
Because these xampp versions also support Mysqli by default.

Categories