I'm currently developing a Web app for the iPad.
So I created the whole "application", with my different html files, my css, my pictures.
Now the next step for me is to be able to cache the files to use the "application" offline.
I follow the advices I found on different websites, with the manifest file and everything.
It seems I'm the only one with this issue, because I searched on Internet an answer to my issue, but I didn't find anything.
So I created my manifest file (ipad.manifest) which looks like this :
$CACHE MANIFEST
$/WebApp/home-start.htm
$/WebApp/accommodation.htm
$/WebApp/accommodation2.htm
$/WebApp/dining.htm
$/WebApp/entertainment.htm
$/WebApp/general.htm
$/WebApp/home.htm
$/WebApp/shopping.htm
$/WebApp/sights.htm
$/WebApp/sports.htm
$/WebApp/css/screen3.css
$/WebApp/Player/CanalVenetian.mp4
$/WebApp/Player/DancingWater.mp4
$/WebApp/Player/NaCha.mp4
$/WebApp/Player/NaCha2.mp4
$/WebApp/Player/Opening.mp4
$/WebApp/Player/previewhome.jpg
$/WebApp/Player/previewsights.jpg
$/WebApp/Player/previewvenetian.jpg
$/WebApp/Player/Venetian.mp4
$/WebApp/Player/video.js
$/WebApp/Player/Zaia.mp4
$/WebApp/iPad/startup.png
$/WebApp/iPad/pixel.gif
$/WebApp/iPad/asktt-ipad-accommodation2.jpg
$/WebApp/iPad/asktt-ipad-camera.jpg
$....
I tried with both, relative and absolute links, and it's still not working.
And in every html files I added :
$<!DOCTYPE html>
$<html manifest="ipad.manifest">
$<head>
When I go to the website with the iPad and click on "add to home screen", it adds the icon on the home screen but didn't download the content. So each time I open the application it starts to load everything....
When I tried on desktop browsers it didn't ask me to cache the content on my computer.
I added an header "content/type : text/manifest" for my mime type files on my server.
But I don't understand why it doesn't cache anything, or doesn't even ask me if I want to cache the files???
Does someone have an idea ? Or had the same issue ?
try with this, put it on the root of your app and name it manifest.php and add it to your html web app with
php file start here
$hashes="";
$dir = new RecursiveDirectoryIterator(".");
foreach(new RecursiveIteratorIterator($dir) as $file){
if ($file->IsFile() &&
$file != "./manifest.php" &&
substr($file->getFilename(),0,1) != ".")
{
echo $file . "\n";
$hashes .= md5_file($file);
}
}
echo "# Hash:" . md5($hashes) . "\n";
?>
php file ends here
Related
I need to manipulate the openldap server database file for an app feature. I noticed that on shell it can find the openldap database file olcDatabase={1}bdb.ldif. But when I run the script from web browser from a windows host, it can not find the file. So I wrote my test script as below.
<?php
$filename = '/etc/openldap/slapd.d/cn=config/olcDatabase={1}bdb.ldif';
file_put_contents('/var/log/file_path_data', realpath($filename));
if (file_exists($filename))
echo "find the file";
else
echo "don't find the file";
?>
When it is run from web, it can not find the file at all and escaping special characters doesn't help. I also used %3D or \x3D to replace "=" in file path for example (see http://www.ascii-code.com/), but it doesn't help either. There is no any single error reported from web browswer when it can not find the file.
This may be related to utf8 encoding or something like this in windows environment but i m not able to figure out how to fix this problem. Highly apprecitate any tips and solutions. Thanks a lot in advance!
At first just try read your file from a little bit less subdirectories.
When you find out whats chars your web server don't handle
For example create this test files :
1) $filename = '/etc/openldap/slapd.d/olcDatabase={1}bdb.ldif';
2) $filename = '/etc/openldap/slapd.d/olcDatabase=bdb.ldif';
And try read them
I am developing an application which will work under file:// URI for safety reasons. It needs to link to other files in my computer as well as read content of some directories.
While reading specific files seems simple, I am unable to find a way to read directory listing. Is there any way to do this.
I have a local web server installed which can be used as a proxy for directory listing. But I ideally don't want to use this approach
Note: I don't want to develop it as Chrome extension, or use a sandbox filesystem. I need to read directory listing of any folder present
Here is a simple program if you have or can install a local web server.
<?php
header('Access-Control-Allow-Origin: null');
$key = "very_long_key";
if (isset($_GET['dir'], $_GET['key']) && is_dir($_GET['dir']) && $_GET['key'] == $key) {
$dir = $_GET['dir'];
$files = glob($dir . '\*.{jpg,jpeg,png,gif,webm,mp4}', GLOB_BRACE);
echo json_encode($files);
} else {
var_dump($_GET);
}
You can use AJAX to make request to it. But still I am looking for a way to do it without need of a web server if anybody knows
Is there any way to get the current opened tab in a browser (firefox at least) using bash .
In other words, the url of the tab that called the bash script from the file browser (incorporated in that page)
Firefox changed the way it stores urls on the hard drive in version 33.
I wrote this php script to search for opened tabs. I used php, so you'll need php5-cli (or newer) package installed.
You'll need to ajust the $displayOnlyLastActiveUrl to fit your needs: set to false to display all opened url, true for last active opened URL
the script might need to be improved, but it fits my needs.
known limitations:
migth not look in the good profile if you have multiple profiles set in firefox.
might takes up to 10 seconds to update
if you choose to output all urls, some closed tabs may appear
just create a php file with the above content and run it within shell with php yourfile.php
<?php
//
// Display curent opened URLs in firefox.
// Author: Julien Marin (malinuxtele[AT]tuxfamily[DOT]org)
// Licence: GPL 3
//
$displayOnlyLastActiveUrl=true; //set to false to display all opened url, true for last active opened URL
//Search for restore.js (might need to be improved for multiprofiles environement...)
if (!$profileIniContents=fopen(getenv("HOME")."/.mozilla/firefox/profiles.ini", "r")) trigger_error("unable to open profiles file", E_USER_ERROR);
$profile="";
$ar_match=array();
while ($ligne=fgets($profileIniContents))
if (preg_match("/Path=([^.]*)[.]default/", $ligne, $ar_match))
$profile=$ar_match[1];
//Open recovery.js file
if(! $recoveryFileHandle=fopen(getenv("HOME")."/.mozilla/firefox/$profile.default/sessionstore-backups/recovery.js", "r")) trigger_error("unable to open recovery.js file", E_USER_ERROR);
$recoveryData=json_decode(fread($recoveryFileHandle, 4000000), true);
//parse data
$ar_tabs=array();
foreach ($recoveryData["windows"] as $actWindow)
foreach ($actWindow["tabs"] as $actTabGroup)
{
$lastAccess=$actTabGroup["lastAccessed"];
foreach ($actTabGroup["entries"] as $actTabEntry)
if(!$displayOnlyLastActiveUrl) echo($actTabEntry["url"]."\n");
else $ar_tabs[$lastAccess]=$actTabEntry["url"];
}
//search last URL
if ($displayOnlyLastActiveUrl)
{
ksort($ar_tabs);
echo array_pop($ar_tabs);
}
?>
I've found this by chance :
#!/bin/bash
for var in "$#"
do
#
#
done
$# contains the url of the tab.
I am trying to create thumbnail pics using GD lib in Cake PHP.
I can write the resized thumbnail to the tmp directory, and create the sensible URL to show the image from the tmp directory:
//set up empty GD resource
$tmp = imagecreatetruecolor(200*$iw/$ih, 200);
//create thumbnail image in the empty GD resource
imagecopyresampled($tmp, $src, 0, 0, 0, 0,200*$iw/$ih, 200, $iw, $ih);
//build full path to thumbnail in the cakephp tmp directory
$thumbfile = APP.'tmp/thumb.jpg';
//build URL path to the same thumbnail
$thumblink = $this->webroot.'tmp/thumb.jpg';
//write jpeg to the tmp directory
$return=imagejpeg($tmp,$thumbfile);
//write out the image to client browser
echo "<img=\"$thumblink\" alt=\"thumb\" height=\"200\" width=\"200*$iw/$ih\">";
The thumbnail gets created and written to the tmp directory, but when I try to access the URL I get the following error message:
Error: TmpController could not be found.
Error: Create the class TmpController below in file: app/Controller/TmpController.php
Obviously I have a routing error - Cake tries to call the tmp controller, in stead of looking in the tmp direcectory. How can I fix this, or is there an alternative way to serve temporary thumbnails using GD lib?
I am planning to create unique thumbnails per session or user, but I need to get this working first.
Routing in Config/routes.php:
Router::connect('/', array('controller' => 'MsCake', 'action' => 'index'));
Router::connect('/pages/*', array('controller' => 'pages'));
CakePlugin::routes();
I looked at ThumbnailHelper, but that doesn't use GD Lib. I also need to be able to access files stored on non-apache accessible directories from outside, but I can't even access any temporary symbolic links to get to them. eg.
create a temporary symbolic link in the tmp directory, pointing to the file in question.
create a HTML link, pointing to the symbolic link using $this->webroot.'tmp/link-to-myfile', as above
...and I get the same error as above - Error: TmpController could not be found.
Don't do that
If you do anything to make files in the tmp dir web-accessible - you're severely lowering your site's security. Things in the tmp directory are never supposed to be web accessible.
Put your images in the webroot
A better idea is to put your temporary images in the webroot directory - which is the only directory that is ordinarily web accessible. For example:
$filename = md5($userId);
$thumbfile = APP.'webroot/img/cache/' . $filename . '.jpg';
...
$url = '/img/cache/' . $filename . '.jpg';
Or route to a controller action
Alternatively, route to a controller action to handle the request using the media view class. Note however though, that serving images with php is not free - there can be a noticable delay while your request is processed - where'as pointing at a static file does not have this cost/risk since it's just the webserver taking care of serving the content.
Since it's temporary, what you could do is to display the image as a data url instead of to the tmp directory, like so (replace from after imagecopyresampled() call):
ob_start();
imagepng($tmp);
$contents = ob_get_contents();
ob_end_clean();
imagedestroy($tmp);
//write out the image to client browser
echo "<img src='data:image/png;base64,".base64_encode($contents)."' alt='thumb' height='200' width='".(200*$iw/$ih)."'>";
This uses a bit more bandwidth since the image is base64 encoded rather than sent as binary.
I am writing a simple file uploader in CodeIgniter 2.0.2. Pasting code below.
Under certain conditions the browser hangs during this upload and I get "waiting for localhost" in the browser status bar (identical behavior in FF and Chrome).
I have verified that the file is being uploaded to the Windows temporary folder (the complete file), but the process gets stuck after that.
It appears that the condition for the bug is file size. But my php.ini has all the right settings for uploading files, and I still get the hang with a 700k file.
This bug occurs only when I run it on Windows 7 Apache, not on an Ubuntu box.
The suggested to me that some paths in the php.ini may be incorrectly set.
Apache log files have not been much help here because there is no error thrown.
I have tried using Chrome developer panel to debug but haven't turned up anything useful.
I am currently trying to get XDebug working, but since no error is thrown and the process doesn't complete, my expectations are low.
Any suggestions for how to trace this bug?
If there are specific php.ini settings you'd like to see, let me know, don't want to do the big dump.
Controller:
function do_upload_sql(){
// create directory
if (! is_dir(BACKUP_DIR)) {
mkdir(BACKUP_DIR, 0777);
}
// or if it exists and has restricted file permissions, change them
elseif(fileperms(BACKUP_DIR)!=0777){
chmod(BACKUP_DIR, 0777);
}
$config['upload_path'] = BACKUP_DIR;
$config['allowed_types'] = 'backup'; // an SQL backup file type
$config['overwrite'] = TRUE;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload()) // this is the native CI function, probably where the problem is. I can provide some of that code if anyone wants.
{
$data['action'] = 'c_backup_restore/do_upload_sql';
$tab_error = array('error' => $this->upload->display_errors());
$data['error'] = $tab_error['error'];
$this->load->view('common/header');
$this->load->view('v_upload_sql', $data);
}
else
{
echo "success"; // yes it's getting here, but i get no file!
$data = array('upload_data' => $this->upload->data());
$file_upload = $data["upload_data"];
$this->restore_backup($file_upload); // go do something useful with the file
}
}
View:
<p>Select the backup file</p>
<div class="not_success"><?php echo $error;?></div>
<?php echo form_open_multipart($action);?>
<input type="file" name="userfile" size="30" />
<input type="submit" value="Upload" />
</form>
If your error only occurs on windows 7 apache, I think that your issue may be with the "is_dir()" "mkdir()" and "chmod()" commands -- these terminal commands are linux specific and will not work so great on a windows system.
I looked up the documentation on the mkdir() function in the PHP.net Manual at:
http://us.php.net/manual/en/function.mkdir.php
I found this in the comments section:
kendsnyder at gmail dot com 04-May-2007 08:17
When creating directories in Windows, trailing periods (".") are ignored. for example:
<?php
mkdir('c:/Buck Jr.',0755); // on Windows creates "c:/Buck Jr"
mkdir('c:/Elipses...',0755); // on Windows creates "c:/Elipses"
mkdir('c:/php.com',0755); // on Windows creates "c:/php.com"
?>
This is a Window's quirk, not a php shortcoming--meaning that you get the same results from a Window's command prompt.
So it seems it will work... but you are likely to have to futz with it to find the flavor that Windows systems prefer. Also it seems that you must specify the root drive on which to make the directory, e.g.: 'c:\somedir'
Also of interest, I did a quick google search and discovered that PHP has published a bug around the functionality you are using, specifically related to forward vs. back slashes of the windows vs. linux systems:
https://bugs.php.net/bug.php?id=29797
Here is a StackOverflow post related to your question:
PHP mkdir(), chmod() and Windows
So to summarize:
On a windows based web server, include the drive that the directory will be placed on
File Permissions on Windows are different from Linux (Windows doesn't have a chmod or file permissions structure like Linux!) Although from what I can tell Windows is supposed give a folder the equivalent of a 777 permissions level -- but this functionality seems buggy and error prone. But this also means that using the chmod() function on a windows system, you will get unpredictable results. For more info consult the PHP Manual: http://php.net/manual/en/function.chmod.php
Remember to use backslashes rather than forward slashes for the directory path, as Windows systems use back slashes, whereas Linux uses forward slashes.
When PHP creates a directory it uses the permissions that were granted to the user account that PHP is running under, which means that you may have to dig into windows to find what user permissions level your windows 7 Apache/PHP is running under and make that change there. I know, what a pain, right?
One final thing: mkdir() function returns true if the directory creation was successful and false if not -- you may want to be testing for that condition before proceeding with the rest of your code, because if the directory doesn't properly get created, all the rest of your code that relies on that directory existing is going to fail. Ultimately I think your browser is hanging upon submit because it is trying to access a function through PHP which there is no support for on Windows (chmod). Perform the function calls within a "Try/Catch" block to catch any exceptions that occur so that you can print them to screen or a log file if necessary:
$proceed = false;
try
{
// create directory
if (! is_dir(BACKUP_DIR)) {
$proceed = mkdir(BACKUP_DIR, 0777);
}
// or if it exists and has restricted file permissions, change them
elseif(fileperms(BACKUP_DIR)!=0777){
$proceed = chmod(BACKUP_DIR, 0777);
}
}
catch(Exception $e)
{
echo $e->message;
}
if($proceed == TRUE)
{
/*Proceed with your code*/
}
else
{
/*Gracefully fail*/
}
Good luck man, this is why I prefer Linux Boxes for web servers!
Cheers!