0
  1. So from my iOS device, I am planning on uploading a profile pic for the user to the php server. Most likely I will be using new AFNetworking for this. My question is, how big files should I allow on my php side? For security reasons (just to be safe) I don't want to allow absurdly big images. is there a limit which all ios pic sized under? what would happen if user selects a pic which he downloaded from internet or somewhere else and the size is bigger? Is there a way to ensure the file size is reduced (without compromising quality) to under certain size on the client side?

  2. Second question I have - is uploading base64 encoded images smaller in size as compared to regular images?

  3. Last question - on the ios device, is there a way to check the size of an image? I am sure there is some app for this. (without code)

My php backend looks like:

      $target_dir = "/Users/username/foldername/";
      $target_dir = $target_dir . basename( $_FILES["uploadFile"]["name"]);
      $uploadOk=1;

      if ($_FILES["uploadFile"]["size"] > 500000) {
        echo "Sorry, your file is too large.\n";
        $uploadOk = 0;
      } 
      if ($_FILES["uploadFile"]["type"] != "image/png") {
          echo "Sorry, only png files are allowed. Your file type was ". $uploadFile_type;
          $uploadOk = 0;
      } 
      if ($uploadOk == 1){
          if (move_uploaded_file($_FILES["uploadFile"]["tmp_name"], $target_dir)) {
            echo "The file ". basename( $_FILES["uploadFile"]["name"]). " has been uploaded.\n";
          } else {
              echo "Sorry, there was an error uploading your file.\n";
          }
      }
      else {
              echo "Sorry, there was an error uploading your file.\n";
      }
  • *"what file size image should I allow?"* - That is entirely up to you and what your host will allow. Always check for disk space before letting people upload really big files and as the uploads augment, well... you may eventually end up with no space at all. – Funk Forty Niner Oct 31 '14 at 17:58

1 Answers1

1
  1. That's up to you. First decide the resolution of the image (e.g. 300x300px? Smaller? Bigger?) and then adjust the file size accordingly. For example, you can certainly be sure that a 300x300px jpeg image will be smaller than 200KB, but if you want a 3,000 x 3,000 px image you need to allow a few MBs.

  2. base64 is a form of encoding that uses only 64 characters and thus will be 1/3 bigger than "normal" (non-encoded) binary data.

  3. UIImagePickerController returns a UIImage object to the delegate. You can get the size of the image accessing the size property of that object (it's a CGSize element).

ItalyPaleAle
  • 7,185
  • 6
  • 42
  • 69
  • thanks! What i am really looking for is what's the default size of image which a regular iphone 5 takes with its camera? also this is going to change in later devices I am going to assume? does a camera app itself take different sized image as compared to the camera which pops up when we call the UIImagePickerController's camera? – sudoExclaimationExclaimation Oct 31 '14 at 18:14
  • 1
    You must not assume any fixed size from the iPhone as everything depends on which camera it's using, if the user zooms in (the zoom is only digital), etc. If you want a specific size, you can resize the UIImage object. See: http://stackoverflow.com/questions/2658738/the-simplest-way-to-resize-an-uiimage – ItalyPaleAle Oct 31 '14 at 19:50