PHP code example of didweb / resize
1. Go to this page and download the library: Download didweb/resize library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
didweb / resize example snippets
$resize = $this->get('didweb_resize.acciones');
$resize->upload($nombreArchivo,$entity->getFile());
$resize = $this->get('didweb_resize.acciones');
$resize->CambioNombreImg($nombreViejo,$nombreNuevo);
public function createAction(Request $request)
{
$entity = new Imagen();
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$entity->setSlug($entity->getNombre().'-'.rand(0,99999));
$entity->setExtension();
$em->persist($entity);
$em->flush();
$resize = $this->get('didweb_resize.acciones');
$resize->upload($entity->getSlug().'.'.$entity->getExtension(),$entity->getFile());
return $this->redirect($this->generateUrl('imagen_show', array('id' => $entity->getId())));
}
return array(
'entity' => $entity,
'form' => $form->createView(),
);
}
namespace bancopruebas\BackendBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Imagen
*
* @ORM\Table()
* @ORM\Entity()
*/
class Imagen
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var integer
* @ORM\Column(name="orden", type="integer")
*/
private $orden;
/**
* @var string
* @ORM\Column(name="nombre", type="string", length=255)
*/
private $nombre;
/**
* @var string
* @ORM\Column(name="slug", type="string", length=255)
*/
private $slug;
/**
* @var string
*
* @ORM\Column(name="extension", type="string", length=5)
*/
private $extension;
/**
* @Assert\File(maxSize="6000000")
*/
private $file;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Sets file.
*
* @param UploadedFile $file
*/
public function setFile($file)
{
$this->file = $file;
}
/**
* Get file.
*
* @return UploadedFile
*/
public function getFile()
{
return $this->file;
}
/**
* Set orden
*
* @param integer $orden
* @return Imagen
*/
public function setOrden($orden)
{
$this->orden = $orden;
return $this;
}
/**
* Get orden
*
* @return integer
*/
public function getOrden()
{
return $this->orden;
}
/**
* Set nombre
*
* @param string $nombre
* @return Imagen
*/
public function setNombre($nombre)
{
$this->nombre = $nombre;
return $this;
}
/**
* Get nombre
*
* @return string
*/
public function getNombre()
{
return $this->nombre;
}
/**
* Set slug
*
* @param string $slug
* @return Imagen
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* Get slug
*
* @return string
*/
public function getSlug()
{
return $this->slug;
}
/**
* Set extension
*
* @param string $extension
* @return Imagen
*/
public function setExtension()
{
$nombredelpath=$this->getFile()->getClientOriginalName();
$extension = explode(".",$nombredelpath);
$corte = count($extension)-1;
$extension = $extension[$corte];
$this->extension = $extension;
return $this;
}
/**
* Get extension
*
* @return string
*/
public function getExtension()
{
return $this->extension;
}
}
$bundles = array(
...
new Didweb\Bundle\ResizeBundle\DidwebResizeBundle(),
....
);