RSS
 

What’s the Easter Egg in 1.1?

19 Aug

As we stated in our last blog post about V1.1, there’s an extra feature that requires its own post to explain what it’s all about,  due to its current state it is for medium to advanced users only.

Sending links to the phone is nice, and sending texts can make it easier to write something on your computer or grab some notes and then you’ll have it quickly in the clipboard of your phone.

But there is another feature that can make things easier sometimes…

What about sending files?

Yep, don’t you wish sometimes to being able to quickly send a file or an .apk to your phone without the need to plugin the USB cable or swap out the MicroSD card?

Of course there are other options available, the nice thing is trying to provide alternatives because some people might not want to register with a new company, or you don’t want to use a closed source app, or whatever. We think sending files is a natural progression by integrating this option with FoxToPhone, so this version includes a first experimental version.

How does it work?

First of all: this is disabled by default.
Secondly you just need three things to enable sending files.
- The latest version of FoxToPhone (V1.1)
- Write access to a web server.
- The PHP script below.

You have to set up your own web hosting server and adjust the configuration of the extension before being able to send any file, you can find the full steps a little further down.

The system is quite simple:
You setup a hosting server, accessible to both your computer and your phone (any web hosting service should be suitable), then you can drag&drop a file or folder into the toolbar button, or right click on it and pick the files that you want to send.

The server sends back a url to retrieve the upload, and that url is sent to the phone using the same method FoxToPhone normally sends links.

When the url arrives at the phone, it launches the browser with that URL, detects that it’s a file and starts the download.

Why isn’t it enabled?

Quite simply, Bandwith and Privacy.

There are already lots of people (over 20,000) using this extension, if just a few of them try to send a few hundred Kb or some Mb files, then our servers will go over quota with our hosting provider, so we need to find a proper hosting before everybody can use it. As we have built this extension as our hobby, we cannot afford the potentially massive bandwidth.

And privacy: even if the files are automatically deleted, they are sent through an external server, so people might expect some privacy about the data that they send so we are not going to enable it until we can be sure that everything is OK in that aspect.

Let me enable it for myself!

Ok, here we go. You can use any kind of server, the example script is done in PHP, but you can easily adjust it to any other server language. Remember this is an open source project, and if you do implement a version of this script in another language we only ask that you reference us. However it would be great if you choose to provide it back to the community too.

Save this code as foxtophone.php on your webserver:

<?php
// Folder to store the files
// Adjust it to your server
$filesFolder =  '/home/ ... /files/';

if ($_SERVER['REQUEST_METHOD'] == 'GET'){
 if (isset($_GET['name']) && isset($_GET['type']) && isset($_GET['data']) )
 {
 $fileName = $_GET['name'];
 $mime =  $_GET['type'];
 $data =  $_GET['data'];
 // Safety check
 $data = preg_replace('/[^\dA-F]/i', '', $data);
 }
 else
 {
 echo 'Invalid request';
 exit(1);
 }

 $file = $filesFolder.$data;
//echo $file;

 if (!file_exists($file) || !is_file($file))
 {
 echo 'Invalid file';
 exit(1);
 }

ob_end_clean();
header('Connection: close');
header('Content-Encoding: none');
ob_start();

 header('Content-Type: '.$mime);
 header('Content-Length: '.filesize($file));
 header('Content-Disposition: attachment; filename="'.str_replace('"', '', $fileName).'"');
 // Flush buffers
 while (@ob_end_flush());

 // Send the file
 $fp = fopen($file,'r') ;
 while (! feof($fp)) {
 $buff = fread($fp,4096);
 print $buff;
 }
 fclose($fp);

 // Send the data and flush buffers
 while (@ob_end_flush());
flush();
ob_end_clean();    

 // Delete it and exit
 // The phone makes two requests with GET, they both seem identical, and if we delete the file
 // on the first access then the real download will fail if it's a small file
 // Have to file a bug about this.
 // Let's wait a little so the second request starts and the file is sent there
 sleep(30);

 unlink($file);

 exit();
}

if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
 if (isset($_FILES['upload']))
 {
 $file = $_FILES['upload'];

 // Be careful about all the data that it's sent!!!
 // Check that the user is authenticated, that the file isn't too big,
 // that it matches the kind of allowed resources...
 $name = $file['name'];
 $mime = $file['type'];

 // create a unique filename based on IP and real filename
 $data = md5($_SERVER['REMOTE_ADDR'] . $name . date('H:i:s'));

 $sFilePath = $filesFolder.$data;

 move_uploaded_file( $file['tmp_name'], $sFilePath ) ;

 header('Content-Type: text/xml');
 echo '<?xml version="1.0" standalone="yes"?>';

 echo '<result>';
 echo '<upload>';
 // Url to retrieve the uploaded file.
 echo curPageURL().'?data='.$data.'&amp;type='.urlencode($mime).'&amp;name='.urlencode($name);
 echo '</upload>';
 echo '</result>';
 }
 else
 die('No file has been sent');
}

// Get the current page url
function curPageURL() {
 $pageURL = 'http';
 if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
 $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
 $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}

?>

You have to put a proper path in  $filesFolder to a folder in the server where you have set write permissions in order to store the files.

Now in Firefox type “about:config” into the address bar and press enter. Edit the preference “extensions.sendtophone.fileServerUrl”, putting there the url (something like http://192.168.0.5/foxtophone.php or http://yourdomain.com/foxtophone.php, remember that if you try to use “localhost” the phone will look at itself and not your server).

And you’re ready to go.

Open the context menu of the toolbar and you’ll find two new entries to send files or folder, pick something and it will be sent to your phone.

Please, don’t be harsh on the PHP coding style, I can count with the fingers of my hands the number of PHP pages that I’ve ever written and remember that this is just experimental stuff that isn’t enabled by default.

If you want to repost something about this feature, please keep in mind that this is not meant for the average user, they don’t have a web server at hand so publishing this as an announcement for everyone can lead to confusion because they can’t make it work. We will try to find  a simple and secure file hosting solution for everyone and we would love to hear your suggestions about it.

 
 

Leave a Reply

 


 
  1. Max

    24/08/2010 at 00:53

    Love the concept! I set it up to the point where I’m able to drag a file to the icon in firefox, or right click –> Send Files, but it doesn’t seem to work. The link is pushed to my phone, but when I open it it says download complete but the file seems corrupt. I have tried small text files and larger (600kb) pictures, to no avail. Any tips? This is definitely a great implementation of such a feature!

     
    • paddy

      24/08/2010 at 13:31

      Sometimes there can be issues on the server side with file permissions. On some hosting setups files cannot be uploaded as the user the scripts are running under do not have the right permissions. Please contact your hosting provider to see what settings need to be changed to allow file uploads.

       
    • alfonso

      24/08/2010 at 16:30

      While developing it I found that I had problems due to the server gzipping the contents and the double download by Android, so it didn’t work as expected.

      You should check two things:
      first, open with a text editor the file that has been downloaded to check what’s inside, that can be the main cue.
      Second, edit the php file, for example comment out the “unlink($file);” line

       
  2. carlo

    25/08/2010 at 06:12

    great! just tested, no problem.

    if you use:
    readfile($file);

    instaed of:
    $fp = fopen($file,’r') ;
    while (! feof($fp)) {
    $buff = fread($fp,4096);
    print $buff;
    }
    fclose($fp);

    while (@ob_end_flush());
    flush();
    ob_end_clean();

    is much faster with big files (tested with 2MB mp3)

     
  3. dmacleo

    26/08/2010 at 19:34

    going to play with this in a few moments, cool concept. thank you.

     
  4. dmacleo

    27/08/2010 at 19:33

    been testing with file sizes, seems to be issue starting around 12mb or so.
    not php.ini issue on server either.
    do not see anything in this php that would cause that, possible its a firefox config setting somewhere?

     
    • paddy

      29/08/2010 at 08:46

      I think there may be a 5mb limit, i’ll have to recheck the source

       
      • dmacleo

        31/08/2010 at 00:49

        I have done 8mb ok, I tried a 10 and I forget the results :)

         
      • dmacleo

        31/08/2010 at 00:50

        btw this is very useful :)

         
  5. ICDeadPpl

    09/09/2010 at 10:50

    Seems like I can’t download files with spaces in their names..?

     
    • ICDeadPpl

      09/09/2010 at 10:54

      Sorry, my bad, it’s files thet are large (3,8 MB) that generate “invalid file” error.

       
      • ICDeadPpl

        09/09/2010 at 11:06

        Edited the php.ini to allow larger file sizes.
        Disregard all previous posts!

         
  6. Roffy

    23/09/2010 at 14:44

    Love the app!

    Having a little trouble with the file transfer though.

    When I use it on my main hosting account (Pipeten) the server always returns a 400 error – Bad Request. It does not get as far as executing the script – the script could not even be there or renamed and the same error occurs. I run many other scripts on there without any trouble.

    However, I also have a bit of hosting space with my ISP, and it worked on there first time!

    I’d like to move it to my main hosting area, so if anyone has any clues why the 400 error occurs, I look forward to hearing them.

    Again, cracking app – thanks!

     
    • alfonso

      24/09/2010 at 14:12

      Can you try to use a simple web page that posts a file to that same script to verify that it works?

       
  7. Chris

    03/10/2010 at 08:49

    Hello to the devs!

    Nice idea! You could have simply used drop.io, with that users wouldn’t need to set up a script.
    But for me it’s quite brilliant, deploying the .php-script in the next minutes on my nas.

    GREAT GREAT GREAT idea with sending files, I love you, guys ;)

     
    • alfonso

      05/10/2010 at 16:35

      We looked briefly at this and other options, but in order to include such option in the extension we might need to verify that it’s allowed such usage and that their API does what we need.

      I don’t remember right now why we haven’t included it, but if someone can provide a patch we will be glad to accept it :-) (maybe it was just a matter of time and being tired over all the stuff that we coded those days)

       
  8. FoxToPhone – Enviar Ficheiros/Directorias | Pedro Fonseca

    07/12/2010 at 15:33

    [...] processo de como fazer está todo explicado aqui, mas para o pessoal que não tem alojamento, não lhe apetece ler muito ou simplesmente quer ver [...]

     
  9. GB3

    27/12/2010 at 19:31

    Love the direction you’re taking FoxToPhone! Script works great. For those of you that are having issues upload large files … just add an .htaccess file to the root of your domain and add the following lines:

    php_value upload_max_filesize 20m
    php_value post_max_size 20m

    20m = 20 MB

    Adjust as you see necessary :)

     
  10. Introducing FoxToPhone 1.2 (still in beta) | Fox To Phone

    13/07/2011 at 19:52

    [...] we announced that there was a method in FoxToPhone to enable file transfers by setting a hidden preference. Due [...]