SitePoint Sponsor

User Tag List

Results 1 to 1 of 1
  1. #1
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sending from MIDlet, receiving in PHP on server

    Hello :-)!

    I'd like to send text file from MIDlet on mobile phone to PHP on server. I guess there is no difference from PHP point of view whether it is sent from web browser or mobile phone. However if I send it from web browser, I can write:
    [code=text]<input name="usersfile" type="file">[/code]
    and in .php file on the server:
    [code=text]&usersfile = $HTTP_POST_FILES['usersfile']['tmp_name'];[/code]
    But if I send it from MIDlet:
    [code=text]HttpConnection conn = null;
    String url = "h t t p : / / 87 . 205 . xx . xx / datareceiver . php";[/code]
    (Remove the space-bars from the above address).
    I don't know what to write here:
    [code=text]&usersfile = $HTTP_POST_FILES['!!!!!HERE!!!!!']['tmp_name'];[/code]
    I can post the whole code of MIDlet .java file if needed.

    The other time is when the .php is executed. I guess it is executed every single time I choose 'send' in my MIDlet. But what to do to avoid using any web-browser on the server? I mean I want the server just to receive the file when it is sent, save it in the proper place, follow some mathematical operations on received data and save it in the database. (At this moment it is only receiving and saving). This is what I've got in datareceiver.php:
    Code:
    <html>
    <head>
    	<title> Sending... </title>
    </head>
    <body>
    <h1>File sending...</h1>
    <?php
    
    $usersfile = $HTTP_POST_FILES['usersfile']['tmp_name'];
    $usersfile_name = $HTTP_POST_FILES['usersfile']['name'];
    $usersfile_size = $HTTP_POST_FILES['usersfile']['size'];
    $usersfile_type = $HTTP_POST_FILES['usersfile']['type'];
    $usersfile_error = $HTTP_POST_FILES['usersfile']['error'];
    
    if ($usersfile_error > 0)
    {
    	echo 'Problem: ';
    	switch ($usersfile_error)
    	{
    		case 1: echo 'File size exceeded the value of upload_max_filesize'; break;
    		case 2: echo 'File size exceeded the value of max_file_size'; break;
    		case 3: echo 'File sent only partially'; break;
    		case 4: echo 'No file was sent'; break;
    	}
    	exit;
    }
    
    if ($usersfile_type != application/x-www-form-urlencoded)
    {
    	echo 'Problem: improper file type';
    	exit;
    }
    
    $localization = '/sent/'.$usersfile_name;
    
    if (is_uploaded_file($usersfile))
    {
    	if (!move_uploaded_file($usersfile, $localization))
    	{
    		echo 'Problem: File cannot be copied to the directory';
    		exit;
    	}
    }
    else
    {
    	echo 'Problem: there could've been attack when sending the file. File name: '.$usersfile_name;
    	exit;
    }
    
    echo 'File sent<br /><br />';
    
    $wp = fopen($localization, 'r');
    $myContent = fread($wp, filesize($localization));
    fclose($wp);
    
    echo 'Content of the sent file:<br /><hr />';
    echo $myContent;
    echo '<br /><hr />';
    
    ?>
    </body>
    </html>
    Greetings!
    Last edited by johnyjj2; Sep 25, 2009 at 14:27. Reason: adding some code


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •