upload image using postfile not working

211 views
Skip to first unread message

Riaz Ahmed

unread,
Jun 29, 2015, 7:40:13 PM6/29/15
to mitappinv...@googlegroups.com
in the past i have managed to upload image to server (but that was VPS, now im trying with godaddy server).

Heres the code blocks:
https://www.dropbox.com/s/9gndlxibrg8f85b/uploadimage.jpg?dl=0

Heres the PHP:
<?php

$ACCESSKEY="uhuh";

header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');

if($_GET['p']==$ACCESSKEY){
  // this is the workaround for file_get_contents(...)
  require_once ($_SERVER['DOCUMENT_ROOT'].'/php/PHP_Compat-1.6.0a3/Compat/Function/file_get_contents.php');
 
  $data = php_compat_file_get_contents('php://input');
 
  $filename = $_SERVER['DOCUMENT_ROOT']."/images/".$_GET['filename'];
  
  if (file_put_contents($filename,$data)) {
    if (filesize($filename) !=0) {

      echo "File transfer completed";
           
    } else {
      //header("HTTP/1.0 400 Bad Request");
      echo "Error: File is empty.";
    }
  } else {
    //header("HTTP/1.0 400 Bad Request");
    echo "Error: File transfer failed.";
  }
} else {

  //header("HTTP/1.0 400 Bad Request");
  echo "Error: Access denied";     //reports if accesskey is wrong
}

?>   


When I tried using desktop emulator, it returns error "411: content length required", when i try using connected phone, the filename gets created on the server in right folder too, but the size is always zero and it returns "error transfer failed".

Hope someone can help.

Taifun

unread,
Jun 29, 2015, 7:57:20 PM6/29/15
to mitappinv...@googlegroups.com
thank you for using my snippet, but it also would be nice to add the link where you found 

When I tried using desktop emulator, it returns error "411: content length required", 
see Q6 here for an answer https://puravidaapps.com/postfile.php#q
Taifun

Riaz Ahmed

unread,
Jun 29, 2015, 8:04:35 PM6/29/15
to mitappinv...@googlegroups.com
just tested the same script again with my VPS and it uploaded the file quick and correctly.

So i dont understand

Abraham Getzler

unread,
Jun 29, 2015, 8:37:08 PM6/29/15
to mitappinv...@googlegroups.com
I hope you're using App Inventor 2.

Classic AI is set to stop soon.

ABG

Riaz Ahmed

unread,
Jun 29, 2015, 8:44:57 PM6/29/15
to mitappinv...@googlegroups.com
but its for client, and they have paid for godaddy server so wont want to use a free server.

godaddy is popular no  one else resolve this?

Riaz Ahmed

unread,
Jun 30, 2015, 12:32:07 PM6/30/15
to mitappinv...@googlegroups.com
that solution does nto work for me cant get file upload to work on godaddy using this method, even tried ringing them, were not very useful

Riaz Ahmed

unread,
Jun 30, 2015, 7:07:16 PM6/30/15
to mitappinv...@googlegroups.com
why does this work on my vps and not godaddy is it cos the latter is shared server.
Reply all
Reply to author
Forward
0 new messages