Subir imagenes en laravel 5.1



   AUTOR PREGUNTA

Publicado 31 mayo 2016 - 18:30

Buenas a todos queria hacer una consulta acerca de como subir imagenes en laravel 5.1, ya que necesito manejar algo como un perfil de usuario al registrarse un usuario tiene la opcion de subir una foto de perfil, ya vi muchos tutoriales en san google pero ninguno es muy detallado y/o se saltan muchos pasos.

Si alguien pudiera darme una ayuda seria genial, gracias de antemano.




4 personas más tuvieron esta duda Yo también

 

Publicado 31 mayo 2016 - 20:57

Para subir imágenes o archivos con Laravel, aquí te dejo un enlace que lo explica de forma correcta con todas sus variantes a gusto de cada uno:

 

Por favor Identificate o Registrate para poder ver este contenido

 

Aquí te dejo una parte:

 

 

 

public __construct(string $path, string $originalName, string $mimeType = null, int $size = null, int $error = null, bool $test = false)

Accepts the information of the uploaded file as provided by the PHP global $_FILES.

The file object is only created when the uploaded file is valid (i.e. when the isValid() method returns true). Otherwise the only methods that could be called on an UploadedFile instance are:

  • getClientOriginalName,
  • getClientMimeType,
  • isValid,
  • getError.

Calling any other method on an non-valid instance will cause an unpredictable result.

 

Parameters string $path The full temporary path to the file string $originalName The original file name string $mimeType The type of the file as provided by PHP int $size The file size int $error The error constant of the upload (one of PHP's UPLOADERRXXX constants) bool $test Whether the test mode is active Exceptions FileException If file_uploads is disabled FileNotFoundException If the file does not exist
in 

Por favor Identificate o Registrate para poder ver este contenido

 at line 62
public string|null guessExtension()

Returns the extension based on the mime type.

If the mime type is unknown, returns null.

This method uses the mime type as guessed by getMimeType() to guess the file extension.

Return Value string|null The guessed extension or null if it cannot be guessed See also getMimeType()  
 
in 

Por favor Identificate o Registrate para poder ver este contenido

 at line 83
public string|null getMimeType()

Returns the mime type of the file.

The mime type is guessed using a MimeTypeGuesser instance, which uses finfo(), mimecontenttype() and the system binary "file" (in this *****), depending on which of those are available.

Return Value string|null The guessed mime type (i.e. "application/pdf") See also MimeTypeGuesser  
 
in 

Por favor Identificate o Registrate para poder ver este contenido

 at line 99
public string getExtension()

Returns the extension of the file.

\SplFileInfo::getExtension() is not available before PHP 5.3.6

Return Value string The extension
 
at line 232
public 

Por favor Identificate o Registrate para poder ver este contenido

 move(string $directory, string $name = null)

Moves the file to a new location.

 

Parameters string $directory The destination folder string $name The new file name Return Value

Por favor Identificate o Registrate para poder ver este contenido

A File object representing the new file Exceptions FileException if, for any reason, the file could not have been moved
at line 113
public string|null getClientOriginalName()

Returns the original file name.

It is extracted from the request from which the file has been uploaded. Then it should not be considered as a safe value.

Return Value string|null The original name
at line 126
public string getClientOriginalExtension()

Returns the original file extension

It is extracted from the original file name that was uploaded. Then it should not be considered as a safe value.

Return Value string The extension
at line 146
public string|null getClientMimeType()

Returns the file mime type.

The client mime type is extracted from the request from which the file was uploaded, so it should not be considered as a safe value.

For a trusted mime type, use getMimeType() instead (which guesses the mime type based on the file content).

Return Value string|null The mime type See also getMimeType  
at line 168
public string|null guessClientExtension()

Returns the extension based on the client mime type.

If the mime type is unknown, returns null.

This method uses the mime type as guessed by getClientMimeType() to guess the file extension. As such, the extension returned by this method cannot be trusted.

For a trusted extension, use guessExtension() instead (which guesses the extension based on the guessed mime type for the file).

Return Value string|null The guessed extension or null if it cannot be guessed See also guessExtension() getClientMimeType()  
at line 186
public int|null getClientSize()

Returns the file size.

It is extracted from the request from which the file has been uploaded. Then it should not be considered as a safe value.

Return Value int|null The file size
at line 201
public int getError()

Returns the upload error.

If the upload was successful, the constant UPLOADERROK is returned. Otherwise one of the other UPLOADERRXXX constants is returned.

Return Value int The upload error
at line 213
public bool isValid()

Returns whether the file was uploaded successfully.

 

Return Value bool True if the file has been uploaded with HTTP and no error occurred.
at line 259
static public int getMaxFilesize()

Returns the maximum size of an uploaded file as configured in php.ini

 

Return Value int The maximum size of an uploaded file in bytes
at line 291
public string getErrorMessage()

Returns an informative upload error message.

 

Return Value string The error message regarding the specified error code

 

Publicado 31 mayo 2016 - 21:02

Aquí lo explican práctico en pasos de forma clara:

 

Por favor Identificate o Registrate para poder ver este contenido

 

Aunque es en inglés, a ver si alguien se anima a hacer este tutorial en Solvetic, seguro que ayuda a muchos jeje.