64618

get image size before upload image php

Question:

I want to know the image size in mb but before ulpload do the same. I have:

$errors = array(); $image = $_FILES['image']['name']; $file_tmp = $_FILES['image']['tmp_name']; $image_type = $_FILES['image']['type']; $descricao = $_POST['descricao']; if(empty($image) || $_FILES['image']['size'] >= 1000) { $_SESSION['alert_type'] = -1; $_SESSION['msg_alert'] = "imagem didnt upload!"; } else { //upload }

The problem is to know the file size, the $ _FILES ['image'] ['size'] is not working well. thanks

Answer1:

Before upload you can check like so:

$file_tmp = $_FILES['image']['tmp_name']; $size = filesize($file_tmp);

But do you realize you are expecting the image to be less than a kilobyte in your code example?

Answer2:

Can't you use the function filesize()?

filesize($_FILES['image'])

or

filesize(//enter image url);

I would give you more details but the php.net site is having malware problems

Answer3:

Well the plugin will help you : <a href="http://blueimp.github.io/jQuery-File-Upload/" rel="nofollow">jQuery-File-Upload</a>

Answer4:

Use php <a href="http://php.net/manual/en/function.filesize.php" rel="nofollow">filesize</a> function.You can get the bytes of the file

$imgsize = filesize( '/home/projects/site/1.jpg' );

Recommend

  • Reading complex xml in C#
  • RestEasyClient JAX RS possible resource leak if not done correctly
  • OpenJPA Webspere 7 Log4j configuration
  • Where does the JLS specify that the result of an addition is int if its operands are of smaller type
  • Laravel multi auth - Authentication user provider [] is not defined
  • jQuery Plugin (DataTables) only loads properly on page refresh
  • ExtJs 4: Remote Combobox - Abort Previous Request
  • Wamp, SlimPHP and Htaccess
  • Clicking content below image with higher z-index
  • Unsupported operand types [closed]
  • FormData how to get or set boundary in multipart/form-data - Angular
  • use selectors in variable jquery
  • Display name for nested complex type
  • Add a nofollow attribute to link if no title tag present using PHP
  • Giving uploaded images a unique name for mysqli
  • What is supported by broadcasting in tensorflow? How dimensions matches determined?
  • Multiple Layouts Previews for Android in Eclipse
  • double precision error when converting to scientific notation
  • JQuery Add class to certain list item
  • How do I install a previous version of build tools in addition to the sdk?
  • Jackson Parser: ignore deserializing for type mismatch
  • How to use remove-erase idiom for removing empty vectors in a vector?
  • How to avoid particles glitching together in an elastic particle collision simulator?
  • Recording logins for password protected directories
  • Repeat a vertical line on every page in Report Builder / SSRS
  • Why is an OPTIONS request sent to the server?
  • Splitting given String into two variables - php
  • Check if a string to interpolate provides expected placeholders
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • Matrix multiplication with MKL
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Hits per day in Google Big Query
  • coudnt use logback because of log4j
  • File not found error Google Drive API
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Converting MP3 duration time
  • Conditional In-Line CSS for IE and Others?