How to upload .jpg file in my form Symfony 5 - symfony-forms

Impossible for me to upload .jpg files in Symfony 5.1, i tried many things,
If i search on the mimtype guide in symfony documentation (https://www.iana.org/assignments/media-types/media-types.xhtml), there is no simple.jpg supported, so how can I do this
Its okay for other files formats. last try:
(I would like to upload image and pdf only)
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Validator\Constraints\File;
use Symfony\Component\Validator\Constraints\Image;
class CapebType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', FileType::class, [
'label'=> 'Chargez ma carte carte Capeb',
'required' => true,
'constraints' => [
new File([
'maxSize' => '5M',
'mimeTypes' => [
'image/jpeg,', 'image/pjpeg', 'image/png', 'image/gif', 'image/jpg',
'application/pdf',
'application/x-pdf',
],
'mimeTypesMessage' => 'Le fichier n\'est pas valide, assurez vous d\'avoir un fichier au format PDF, PNG, JPG, JPEG)',
]),
]
])
->add('submit', SubmitType::class, [
'label'=> 'Envoyez ma carte CAPEB',
])
;
}

Simple, need juste to add image/x
$builder
->add('name', FileType::class, [
'label'=> 'Chargez ma carte carte Capeb',
'required' => true,
'constraints' => [
new File([
'maxSize' => '5M',
'mimeTypes' => [
'image/*',
'application/pdf',
'application/x-pdf',
],
'mimeTypesMessage' => 'Le fichier n\'est pas valide, assurez vous d\'avoir un fichier au format PDF, PNG, JPG, JPEG)',
]),
]
])
->add('submit', SubmitType::class, [
'label'=> 'Envoyez ma carte CAPEB',
])
;

Related

youtube api search respond unexpected data

We are using youtube API for searching our own video files, and the search result responds with data that has no information about the query search, for example:
search: cultura
result: some videos has not cultura in the title, description or tags
API call for video list:
https://www.googleapis.com/youtube/v3/search?key=KEY&channelId=CHANNELID&part=snippet&order=date&q=cultura&maxResults=50
Response:
"items" => array:50 [▼
0 => array:4 [▼
...
"snippet" => array:8 [▼
...
"title" => "Primavera"
"description" => "Arroyo y cascada del rio Castaños en la cara norte del Eretza ([eitb.com][g1] [tiempo-naturaleza] [ bizkaia] [ galdames] [alberto-zorrilla] [1755] [tiemponaturaleza] )
...
API call for video information:
https://www.googleapis.com/youtube/v3/videos?key=KEY&channelId=CHANNELID&part=snippet%2CcontentDetails&id=ID
...
"title": "Primavera",
"description": "Arroyo y cascada del rio Castaños en la cara norte del Eretza ([eitb.com][g1] [tiempo-naturaleza] [ bizkaia] [ galdames] [alberto-zorrilla] [1755] [tiemponaturaleza] )",
...
"tags": [
"category2:tiemponaturaleza",
"category:tiempo-naturaleza",
"city:galdames",
"domain:eitb.com",
"id_user:1755",
"province:bizkaia",
"type:g1",
"username:alberto-zorrilla"
],
"categoryId": "22",
"liveBroadcastContent": "none",
"localized": {
"title": "Primavera",
"description": "Arroyo y cascada del rio Castaños en la cara norte del Eretza ([eitb.com][g1] [tiempo-naturaleza] [ bizkaia] [ galdames] [alberto-zorrilla] [1755] [tiemponaturaleza] )"
}
}
...
,
Some help will be appreciated :)

How can I access value in deeply nested hash in Ruby?

Could someone help me to access "value" in this deeply nested hash:
hash = {
"data" => {},
"content" => [
{
"data" => {},
"content" => [
{
"data" => {},
"marks" => [],
"value" => "est ce que j'arrive à te choper",
"nodeType" => "text"
}
],
"nodeType" => "paragraph"
}
],
"nodeType" => "document"
}
You can get value with dig
hash.dig('content', 0, 'content', 0, 'value')
#=> "est ce que j'arrive à te choper"

Mandrill- Attachments not sending attachment

I am attempting to send a small rtf attachment through Mandrill. I have created the following json and tried it using the API test page. The attachment is base 64 encoded. The API reports no error and the email comes through but with no attachment. What am I doing wrong?
{
"attachments": [
{
"type": "application/rtf",
"name": "test.rtf",
"content": "e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZGVmZjBcZGVmbGFuZzIwNTd7XGZvbnR0Ymx7XGYwXGZuaWxcZmNoYXJzZXQwIENhbGlicmk7fX0NCntcKlxnZW5lcmF0b3IgTXNmdGVkaXQgNS40MS4yMS4yNTEwO31cdmlld2tpbmQ0XHVjMVxwYXJkXHNhMjAwXHNsMjc2XHNsbXVsdDFcbGFuZzlcZjBcZnMyMiB0aGlzIGlzIGEgdGVzdCBzZW5kaW5nIGZpbGVccGFyDQp9DQoA"
}
],
"message": {
"html": "<html>\r\n<body>test data</body>\r\n</html>\r\n",
"subject": "Cloud Demo",
"from_email": "jklovanc#hotmail.com",
"preserve_recipients": true,
"text": "",
"to": [
{
"type": "to",
"name": "",
"email": "jklovanc#hotmail.com"
}
],
"from_name": "",
"headers": {
"reply-to": "jklovanc#hotmail.com"
}
},
"key": #mykey#,
"async": false
}
Attachments are part of the message object, so the attachments parameter should be nested under the message instead of at the same level. It should look like this instead:
{
"message": {
"attachments": [
{
"type": "application/rtf",
"name": "test.rtf",
"content": "e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZGVmZjBcZGVmbGFuZzIwNTd7XGZvbnR0Ymx7XGYwXGZuaWxcZmNoYXJzZXQwIENhbGlicmk7fX0NCntcKlxnZW5lcmF0b3IgTXNmdGVkaXQgNS40MS4yMS4yNTEwO31cdmlld2tpbmQ0XHVjMVxwYXJkXHNhMjAwXHNsMjc2XHNsbXVsdDFcbGFuZzlcZjBcZnMyMiB0aGlzIGlzIGEgdGVzdCBzZW5kaW5nIGZpbGVccGFyDQp9DQoA"
}
],
"html": "<html>\r\n<body>test data</body>\r\n</html>\r\n",
....
<?php
//It works for me! good luck
/*LIBS*/
include 'lib/mandrill-api-php/src/Mandrill.php';
$mandrill = new Mandrill('YOUR API KEY HERE');
/*ADMIN AND USER EMAIL*/
$admin_email = 'your_email#your_domain.com';
$client_email = 'the_email_of_the_client#mail.com';
/*attach PDF with base64_encode */
$attachment = file_get_contents('the_route_to_your_pdf'); // https://yourdomain/pdf_folder/mypdf.pdf
$attachment_encoded = base64_encode($attachment);
try{
$user_message = array(
'subject' => 'Your subject',
'from_email' => $admin_email,
'from_name' => 'my_domain_for_example',
'html' => '<p>HTML template</p>',
'to' => array(array('email' => $client_email, 'name' => 'Recipient 1')),
'merge_vars' => array(array(
'rcpt' => 'recipient1#domain.com',
'vars' =>
array(
array(
'name' => 'FIRSTNAME',
'content' => 'Recipient 1 first name'),
array(
'name' => 'LASTNAME',
'content' => 'Last name')
))),
'attachments' => array(
array(
'content' => $attachment_encoded,
'type' => "application/pdf",
'name' => 'the_name_of_the_attach.pdf',
))
);
$res_user_mandrill = $mandrill->messages->send($user_message, $async=false, $ip_pool=null, $send_at=null);
} catch(Mandrill_Error $e) {
}
?>

how to return a xml from nusoap

I have a webservice created with nusoap, actually returns me a string
i want to do send name and lastname to my web service,my webservice must save this information and give me an id( autoincrement) y it does, but I want something like this
send:
nombrepersona ="ozzy"
apellidopersona="osbourne"
I get the id(autoincrement), example
1
but i want a xml something like
<id>1</id>
or
<id>1</id>
<name>ozzy</name>
<lastname>osbourne</lastname>
or
<response>
<id>1</id>
<name>ozzy</name>
<lastname>osbourne</lastname>
</response>
consume from my webservice
<?php
error_reporting(1);
require_once('lib/nusoap.php');
$client = new nusoap_client("http://localhost/nusoap/server3.php?wsdl",'wsdl');
$nombre="ozzy";
$apellido="osbourne";
$params =array(
'nombrepersona'=>$nombre,
'apellidopersona'=>$apellido);
$result = $client->call('insertar',array($params));
?>
definition from my method
<?php
$server->wsdl->addComplexType(
'Persona',
'complexType',
'struct',
'all',
'',
array(
'nombrepersona' => array('name' => 'nombrepersona', 'type' => 'xsd:string'),
'apellidopersona' => array('name' => 'apellidopersona', 'type' => 'xsd:string')
)
);
$server->wsdl->addComplexType(
'ArrayOfPersona',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:Persona[]')
),
'tns:Persona'
);
$server->register(
'insertar', // Nombre del método
array('datos' =>'tns:Persona'), // Parámetros de entrada
array('return' => 'xsd:string'), // Parámetros de salida
SOAP_SERVER_NAMESPACE, // Nombre del workspace
SOAP_SERVER_NAMESPACE.'#insertar', // Acción soap
'rpc', // Estilo
'encoded', // Uso
'Insertar datos de la persona' // Documentación
);
?>
function
<?php
function insertar($datos)
{
require_once('conectar.php');
mysql_select_db($database,$conexion);
mysql_query("SET NAMES 'utf8'");
$query="INSERT INTO personas (`nombrep`,`apellidop`) VALUES('".$datos['nombrepersona']."','".$datos['apellidopersona']."')";
$record=mysql_query($query,$conexion) or die ((mysql_error()));
$id=mysql_insert_id();
return $id;
}
?>
solution, definition output must be like this:
array('response'=>'XSD:Array')
and return of function like this:
return array('id'=>$id , etc);

How can i add parameter in mandrill html text?

Is there any way to include the parameter i html portion of mandrill ?
I am not using template.
here is my code.
$mandrill = new Mandrill('YOUR_API_KEY');
$message = array(
'html' => '<p>here is my email</p>',
'text' => 'Example text content',
'subject' => 'example subject',
'from_email' => 'message.from_email#example.com',
'from_name' => 'Example Name',
'to' => array(
array(
'email' => 'recipient.email#example.com',
'name' => 'Recipient Name',
'type' => 'to'
),
array(
'email' => 'recipient.email#example.com',
'name' => 'Recipient Name',
'type' => 'to'
)
),
What i want to do is to add a parameter to the html content.
'html' => '<p>here is my email{ param}</p>', // this line
How can i do this ?
Thanks
Sounds like you're looking to use Mandrill merge tags.
You can insert merge tags into your HTML content and have it inject personalized information for each recipient. They can be used in your content with the format *|MERGETAG|* and by defining "merge_vars" in your message array.
Here's an example from their docs:
"message": {
"global_merge_vars": [
{
"name": "var1",
"content": "Global Value 1"
}
],
"merge_vars": [
{
"rcpt": "emailadress#domain.com",
"vars": [
{
"name": "fname",
"content": "John"
},
{
"name": "lname",
"content": "Smith"
}
]
}
],
source:
http://help.mandrill.com/entries/21678522-How-do-I-use-merge-tags-to-add-dynamic-content-
In testing a bit, Mandrill actually supports a few merge tags "out of the box", so you should just be able to add *|EMAIL|* into your HTML content and it'll pull that email address in from your TO array.

Resources