the dreaded “Warning: imagecreatefromjpeg() : ‘/tmp/filename’ is not a valid JPEG file in /phpfile.php on line xxx”

After a little digging around on Google I found this bug report. It seems that the GD library is less tolerant of buggy JPEG files than other programs. The solution suggested was to set GD to ignore JPEG error’s before processing the image, like this: ini_set(“gd.jpeg_ignore_warning”, 1); Hopefully that will work for you. One other … Read more

How to upload string as file with jQuery or other js framework

Here’s how to do it without manually building the multi-part request body: var s=”some string data”; var filename=”foobar.txt”; var formData = new FormData(); formData.append(‘file’, new File([new Blob([s])], filename)); formData.append(‘another-form-field’, ‘some value’); $.ajax({ url: ‘/upload’, data: formData, processData: false, contentType: false, type: ‘POST’, success: function () { console.log(‘ok’); }, error: function () { console.log(‘err’); // replace … Read more

PHP upload image

The code overlooks calling the function move_uploaded_file() which would check whether the indicated file is valid for uploading. You may wish to review a simple example at: http://www.w3schools.com/php/php_file_upload.asp

Compress camera image before upload

Take a look over here: ByteArrayOutputStream to a FileBody Something along these lines should work: replace File file = new File(miFoto); ContentBody foto = new FileBody(file, “image/jpeg”); with Bitmap bmp = BitmapFactory.decodeFile(miFoto) ByteArrayOutputStream bos = new ByteArrayOutputStream(); bmp.compress(CompressFormat.JPEG, 70, bos); InputStream in = new ByteArrayInputStream(bos.toByteArray()); ContentBody foto = new InputStreamBody(in, “image/jpeg”, “filename”); If file size … Read more