How to check file MIME type with javascript before upload?
I have read this and this questions which seems to suggest that the file
MIME type could be checked using javascript on client side. Now, I
understand that the real validation still has to be done on server side. I
want to perform a client side checking to avoid unnecessary wastage of
server resource.
To test whether this can be done on client side, I changed the extension
of a JPEG test file to .png and choose the file for upload. Before sending
the file, I query the file object using a javascript console:
document.getElementsByTagName('input')[0].files[0];
This is what I get on Chrome 28.0:
File {webkitRelativePath: "", lastModifiedDate: Tue Oct 16 2012 10:00:00
GMT+0000 (UTC), name: "test.png", type: "image/png", size: 500055…}
It shows type to be image/png which seems to indicate that the checking is
done based on file extension instead of MIME type. I tried Firefox 22.0
and it gives me the same result. But according to the W3C spec, MIME
Sniffing should be implemented.
Am I right to say that there is no way to check the MIME type with
javascript at the moment? Or am I missing something?
Sunday, 18 August 2013
Turning all events .off() and .on() in jQuery
Turning all events .off() and .on() in jQuery
I'm looking at using .off() and .on() to turn event handlers off and on in
jQuery.
I can turn the all attached event handlers off perfectly by using:
$('.eventone').off();
or as a multiple selector:
$('.eventone, .eventtwo, .eventthree').off();
However, I'm not getting all (or even any) event handlers to turn back on.
I'm using this:
$('.eventone, .eventtwo, .eventthree').on();
Is there something I'm doing wrong?
Do I actually have to declare every event that's associated with the class
in order to turn it back on?
I'm looking at using .off() and .on() to turn event handlers off and on in
jQuery.
I can turn the all attached event handlers off perfectly by using:
$('.eventone').off();
or as a multiple selector:
$('.eventone, .eventtwo, .eventthree').off();
However, I'm not getting all (or even any) event handlers to turn back on.
I'm using this:
$('.eventone, .eventtwo, .eventthree').on();
Is there something I'm doing wrong?
Do I actually have to declare every event that's associated with the class
in order to turn it back on?
Saturday, 17 August 2013
Magento: Including a file in Easytabs template file
Magento: Including a file in Easytabs template file
I want to customise the Magento Easytabs plugin. I want to include n
.phtml file in the
app/design/frontend/default/default/template/easytabs/tabs.phtml file of
Magento Easytabs plugin.
How can I do that?
I want to customise the Magento Easytabs plugin. I want to include n
.phtml file in the
app/design/frontend/default/default/template/easytabs/tabs.phtml file of
Magento Easytabs plugin.
How can I do that?
How to get FFXIV Gil Discount Coupons?
How to get FFXIV Gil Discount Coupons?
FFXIV is a wonderful online game. Players look forward to playing the
game. Players can get some ffxiv gil to enjoy the game. How to get FFXIV
Gil at discount price?Come to http://www.ff14gil.com/faq and there are
cheap ffxiv gil for sale. players can get some FFXIV Gil discount coupons
and help them save money.
FFXIV is a wonderful online game. Players look forward to playing the
game. Players can get some ffxiv gil to enjoy the game. How to get FFXIV
Gil at discount price?Come to http://www.ff14gil.com/faq and there are
cheap ffxiv gil for sale. players can get some FFXIV Gil discount coupons
and help them save money.
Database issue with SQLite
Database issue with SQLite
I have been working with a few different database examples. Every example
i am using to try to learn about SQLite databases i am getting the exact
same error. I have already tried to research this and cannot find my exact
error anywhere.
Thanks for any help below is the code and the error i am getting
DatabaseHandler db = new DatabaseHandler(this);
I am getting unreachable code.
in my Database Handler.java file i do have the public class Database
Handler (one word).
Thanks again.
I have been working with a few different database examples. Every example
i am using to try to learn about SQLite databases i am getting the exact
same error. I have already tried to research this and cannot find my exact
error anywhere.
Thanks for any help below is the code and the error i am getting
DatabaseHandler db = new DatabaseHandler(this);
I am getting unreachable code.
in my Database Handler.java file i do have the public class Database
Handler (one word).
Thanks again.
Java Scanner delimiter doesn't split the last section
Java Scanner delimiter doesn't split the last section
/* txt file
Rolling Stone#Jann Wenner#Bi-Weekly#Boston#9000
Rolling Stone#Jann Wenner#Bi-Weekly#Philadelphia#8000
Rolling Stone#Jann Wenner#Bi-Weekly#London#10000
The Economist#John Micklethwait#Weekly#New York#42000
The Economist#John Micklethwait#Weekly#Washington#29000
Nature#Philip Campbell#Weekly#Pittsburg#4000
Nature#Philip Campbell#Weekly#Berlin#6000
*/
public class Zines {
public static void main(String[] args) throws
FileNotFoundException {
Scanner input = new Scanner(new File("txt.file"));
input.useDelimiter("#");
while(input.hasNext()) {
String title = input.next();
String author = input.next();
String publisher = input.next();
String city = input.next();
String line = input.nextLine();
//int dist = Integer.valueOf(line);
System.out.println(line);
}
}
}
Output is: "#9000 "#8000 "#10000 "#42000 "#29000 "#4000 "#6000
Refrain from the quotations marks! The question here is why does the #'s
still appear after using the delimiter?
/* txt file
Rolling Stone#Jann Wenner#Bi-Weekly#Boston#9000
Rolling Stone#Jann Wenner#Bi-Weekly#Philadelphia#8000
Rolling Stone#Jann Wenner#Bi-Weekly#London#10000
The Economist#John Micklethwait#Weekly#New York#42000
The Economist#John Micklethwait#Weekly#Washington#29000
Nature#Philip Campbell#Weekly#Pittsburg#4000
Nature#Philip Campbell#Weekly#Berlin#6000
*/
public class Zines {
public static void main(String[] args) throws
FileNotFoundException {
Scanner input = new Scanner(new File("txt.file"));
input.useDelimiter("#");
while(input.hasNext()) {
String title = input.next();
String author = input.next();
String publisher = input.next();
String city = input.next();
String line = input.nextLine();
//int dist = Integer.valueOf(line);
System.out.println(line);
}
}
}
Output is: "#9000 "#8000 "#10000 "#42000 "#29000 "#4000 "#6000
Refrain from the quotations marks! The question here is why does the #'s
still appear after using the delimiter?
How to prevent concurrent streaming
How to prevent concurrent streaming
I have written an app for a radio station, that is working well. If I
click to go back to the desktop and click to activate the application
again, it causes the app to stream again, resulting in 2 streams running
concurrently.
Here is my code;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.setTitle("Standart FM");
startButton = (Button) findViewById(R.id.buttonBasla);
facebookButton = (Button) findViewById(R.id.buttonFacebook);
twitterButton = (Button) findViewById(R.id.buttonTwitter);
Intent myService = new Intent(this, MyMediaPlayerService.class);
pd = new ProgressDialog(MainActivity.this);
mediaPlayer = new MediaPlayer();
if (isOnline()) {
pd.setCancelable(false);
pd.setMessage("Yükleniyor...");
pd.show();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource(path);
mediaPlayer.prepareAsync();
} catch (Exception e) {
e.printStackTrace();
}
mediaPlayer
.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
pd.dismiss();
}
});
} else {
....
}
startButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent myService = new Intent(MainActivity.this,
MyMediaPlayerService.class);
if (mediaPlayer.isPlaying()) {
startButton.setBackgroundResource(R.drawable.andplaybtn);
mediaPlayer.stop();
} else {
startButton.setBackgroundResource(R.drawable.andstopbtn);
mediaPlayer.reset();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource(path);
mediaPlayer.prepareAsync();
pd.setCancelable(false);
pd.setMessage("Yükleniyor...");
pd.show();
} catch (Exception e) {
e.printStackTrace();
}
mediaPlayer
.setOnPreparedListener(new
MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
pd.dismiss();
}
});
}
}
});
}
}
How do I solve this problem? How to prevent concurrent streaming in this
Activity? Please help me.
I have written an app for a radio station, that is working well. If I
click to go back to the desktop and click to activate the application
again, it causes the app to stream again, resulting in 2 streams running
concurrently.
Here is my code;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.setTitle("Standart FM");
startButton = (Button) findViewById(R.id.buttonBasla);
facebookButton = (Button) findViewById(R.id.buttonFacebook);
twitterButton = (Button) findViewById(R.id.buttonTwitter);
Intent myService = new Intent(this, MyMediaPlayerService.class);
pd = new ProgressDialog(MainActivity.this);
mediaPlayer = new MediaPlayer();
if (isOnline()) {
pd.setCancelable(false);
pd.setMessage("Yükleniyor...");
pd.show();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource(path);
mediaPlayer.prepareAsync();
} catch (Exception e) {
e.printStackTrace();
}
mediaPlayer
.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
pd.dismiss();
}
});
} else {
....
}
startButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent myService = new Intent(MainActivity.this,
MyMediaPlayerService.class);
if (mediaPlayer.isPlaying()) {
startButton.setBackgroundResource(R.drawable.andplaybtn);
mediaPlayer.stop();
} else {
startButton.setBackgroundResource(R.drawable.andstopbtn);
mediaPlayer.reset();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource(path);
mediaPlayer.prepareAsync();
pd.setCancelable(false);
pd.setMessage("Yükleniyor...");
pd.show();
} catch (Exception e) {
e.printStackTrace();
}
mediaPlayer
.setOnPreparedListener(new
MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
pd.dismiss();
}
});
}
}
});
}
}
How do I solve this problem? How to prevent concurrent streaming in this
Activity? Please help me.
Subscribe to:
Posts (Atom)