<div style='background-color: none transparent;'></div>

World News

Entertainment

image resize in php





Untitled Document




if(!empty($_FILES['image1']['name'])) {
$imagelarge = $_FILES['image1']['tmp_name'];
$imagelargemain = $_FILES['image1']['name'];
$pathInfo = pathinfo($imagelargemain);
$rand = rand(1, 100000000000000);
$name = $rand . '.' . $pathInfo['extension'];
$src = imagecreatefromjpeg($imagelarge);
list($width,$height)=getimagesize($imagelarge);
if ($width > $height) {
$newwidth=600;
$newheight=($height/$width)*$newwidth;
}
elseif ($height > $width) {
$newheight=400;
$newwidth=($width/$height)*$newheight;
}
$center_x = (600/2)-($newwidth/2);
$center_y = (400/2)-($newheight/2);
$tmp=imagecreatetruecolor(600,400);
$white = imagecolorallocate($tmp, 255, 255, 255);
imagefill($tmp, 0, 0, $white);
imagecopyresampled($tmp,$src,$center_x,$center_y,0,0,$newwidth,$newheight,$width,$height);
$filename = WEB_UPLOAD."images/adverts/". $name;
imagejpeg($tmp,$filename,100);
imagedestroy($src);
imagedestroy($tmp);
$image_sql = mysql_query("UPDATE `adverts` SET image1 ='".$name."' WHERE id='".$advert_id."'") or die ("Error updating database");
}





Continue Reading | comments

Sending Email with checkbox list in php




How is your weather now?


Please enter your information:



City:
Month:
Year:


Please choose the kinds of weather you experienced from the list below.

Choose all that apply.



Sunshine

Clouds

Rain

Hail

Sleet

Snow

Wind

Cold

Heat

Fog

Humidity


Anything Else? Please list in the additional weather conditions in box, separated by commas.












and here is the email coding:

if(isset($_POST['email'])) {

$email_to = "youremail@gmail.com";
$email_subject = "

How is your weather now

";

$city = $_POST['city'];
$month = $_POST['month'];
$year = $_POST['year'];
$type = $_POST['type'];
$add = $_POST['add'];

$email_message .= "In ".clean_string($city) . " in the month of " .clean_string($month).clean_string($year)." you observed the following weather: ""\n";

$check =0;
$top = array('Sunshine', 'Clouds', 'Rain', 'Hail', 'Sleet', 'Snow', 'Wind', 'Cold', 'Heat', 'Fog', 'Humidity');

foreach ($_POST['type'] as $type){
echo "
  • $type
  • \r\n";
    }

    ?>

    // create email headers
    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers);
    ?>



    Thank you for contacting us. We will be in touch with you very soon.

    }
    ?>
    Continue Reading | comments

    Creating a Non-Blocking Socket

    public class test
    {
    public static void main(String args[])
    {
    // Create a non-blocking socket and check for connections
    try {
    // Create a non-blocking socket channel on port 8080
    SocketChannel sChannel = createSocketChannel("www.web.com", 8080);

    // Before the socket is usable, the connection must be completed
    // by calling finishConnect(), which is non-blocking
    while (!sChannel.finishConnect()) {
    // Do something else
    System.out.println("wonderful");
    }
    // Socket channel is now ready to use
    }
    catch (IOException e) {
    }
    }

    // Creates a non-blocking socket channel for the specified host name and port.
    // connect() is called on the new channel before it is returned.
    public static SocketChannel createSocketChannel(String hostName, int port) throws IOException
    {
    // Create a non-blocking socket channel
    SocketChannel sChannel = SocketChannel.open();
    sChannel.configureBlocking(false);

    // Send a connection request to the server; this method is non-blocking
    sChannel.connect(new InetSocketAddress(hostName, port));
    return sChannel;
    }
    }
    Continue Reading | comments

    Communicate with proxy server to access a website

    private void establishConnection() {
    try {
    URL url = new URL("http://www.javagalaxy.com");

    //change this to valid proxy server and proxy server port
    InetSocketAddress isa = new InetSocketAddress("192.168.0.12", 8080);

    Proxy proxy = new Proxy(Proxy.Type.HTTP, isa);
    URLConnection urlConnection = url.openConnection(proxy);
    urlConnection.connect();
    InputStream inStream = urlConnection.getInputStream();
    BufferedInputStream binStream = new BufferedInputStream(inStream);

    int i = 0;
    byte[] b = new byte[128];
    File file = new File("index.html");
    FileOutputStream fout = new FileOutputStream(file);

    while (i != -1) {
    i = binStream.read(b);
    if (i > 0)
    fout.write(b);
    System.out.print(b);
    }
    fout.close();

    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    Continue Reading | comments

    Port Scanner

    import java.net.*;
    import java.io.IOException;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;

    public class PScanner {

    public static void main(String[] args) {
    InetAddress ia=null;
    String host=null;
    try {

    host=JOptionPane.showInputDialog("Enter the Host name to scan:\n example: javagalaxy.com");
    if(host!=null){
    ia = InetAddress.getByName(host);
    scan(ia); }
    }
    catch (UnknownHostException e) {
    System.err.println(e );
    }
    System.out.println("Bye from NFS");
    //System.exit(0);
    }

    public static void scan(final InetAddress remote) {
    //variables for menu bar

    int port=0;
    String hostname = remote.getHostName();

    for ( port = 0; port < 65536; port++) {
    try {
    Socket s = new Socket(remote,port);
    System.out.println("Server is listening on port " + port+ " of " + hostname);
    s.close();
    }
    catch (IOException ex) {
    // The remote host is not listening on this port
    System.out.println("Server is not listening on port " + port+ " of " + hostname);
    }
    }//for ends
    }
    }
    Continue Reading | comments

    Ping a server

    import java.io.*;
    import java.net.*;

    public class PseudoPing {
    public static void main(String args[]) {
    try {
    Socket t = new Socket(args[0], 7);
    DataInputStream dis = new DataInputStream(t.getInputStream());
    PrintStream ps = new PrintStream(t.getOutputStream());
    ps.println("Hello");
    String str = is.readLine();
    if (str.equals("Hello"))
    System.out.println("Alive!") ;
    else
    System.out.println("Dead or echo port not responding");
    t.close();
    }
    catch (IOException e) {
    e.printStackTrace();}
    }
    }


    Continue Reading | comments

    Load an audio clip and play it

    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

    public class LoadAudioAndPlay extends JApplet
    {
    private AudioClip sound1, sound2, currentSound;
    private JButton playSound, loopSound, stopSound;
    private JComboBox chooseSound;

    // load the image when the applet begins executing
    public void init()
    {
    Container c = getContentPane();
    c.setLayout( new FlowLayout() );

    String choices[] = { "Welcome", "Hi" };
    chooseSound = new JComboBox( choices );
    chooseSound.addItemListener( new ItemListener()
    {
    public void itemStateChanged( ItemEvent e )
    {
    currentSound.stop();

    currentSound = chooseSound.getSelectedIndex() == 0 ? sound1 : sound2;
    }
    });
    c.add( chooseSound );

    ButtonHandler handler = new ButtonHandler();
    playSound = new JButton( "Play" );
    playSound.addActionListener( handler );
    c.add( playSound );
    loopSound = new JButton( "Loop" );
    loopSound.addActionListener( handler );
    c.add( loopSound );
    stopSound = new JButton( "Stop" );
    stopSound.addActionListener( handler );
    c.add( stopSound );

    sound1 = getAudioClip( getDocumentBase(), "welcome.wav" );
    sound2 = getAudioClip( getDocumentBase(), "hi.au" );
    currentSound = sound1;
    }

    // stop the sound when the user switches Web pages
    // (i.e., be polite to the user)
    public void stop()
    {
    currentSound.stop();
    }

    private class ButtonHandler implements ActionListener
    {
    public void actionPerformed( ActionEvent e )
    {
    if ( e.getSource() == playSound )
    currentSound.play();
    else if ( e.getSource() == loopSound )
    currentSound.loop();
    else if ( e.getSource() == stopSound )
    currentSound.stop();
    }
    }
    }

    Continue Reading | comments

    Media player in Java

    // Uses a Java Media Player to play media files.
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;
    import javax.media.*;

    public class MediaPlayerDemo extends JFrame
    {
    private Player player;
    private File file;

    public MediaPlayerDemo()
    {
    super( "Demonstrating the Java Media Player" );

    JButton openFile = new JButton( "Open file to play" );
    openFile.addActionListener( new ActionListener()
    {
    public void actionPerformed( ActionEvent e )
    {
    openFile();
    createPlayer();
    }
    });
    getContentPane().add( openFile, BorderLayout.NORTH );

    setSize( 300, 300 );
    show();
    }

    private void openFile()
    {
    JFileChooser fileChooser = new JFileChooser();

    fileChooser.setFileSelectionMode( JFileChooser.FILES_ONLY );
    int result = fileChooser.showOpenDialog( this );

    // user clicked Cancel button on dialog
    if ( result == JFileChooser.CANCEL_OPTION )
    file = null;
    else
    file = fileChooser.getSelectedFile();
    }

    private void createPlayer()
    {
    if ( file == null )
    return;

    removePreviousPlayer();

    try
    {
    // create a new player and add listener
    player = Manager.createPlayer( file.toURL() );
    player.addControllerListener( new EventHandler() );
    player.start(); // start player
    }
    catch ( Exception e )
    {
    JOptionPane.showMessageDialog( this, "Invalid file or location", "Error loading file",
    JOptionPane.ERROR_MESSAGE );
    }
    }

    private void removePreviousPlayer()
    {
    if ( player == null )
    return;

    player.close();

    Component visual = player.getVisualComponent();
    Component control = player.getControlPanelComponent();

    Container c = getContentPane();

    if ( visual != null )
    c.remove( visual );

    if ( control != null )
    c.remove( control );
    }

    public static void main(String args[])
    {
    MediaPlayerDemo app = new MediaPlayerDemo();

    app.addWindowListener( new WindowAdapter()
    {
    public void windowClosing( WindowEvent e )
    {
    System.exit(0);
    }
    });
    }


    // inner class to handler events from media player
    private class EventHandler implements ControllerListener
    {
    public void controllerUpdate( ControllerEvent e )
    {
    if ( e instanceof RealizeCompleteEvent )
    {
    Container c = getContentPane();

    // load Visual and Control components if they exist
    Component visualComponent = player.getVisualComponent();

    if ( visualComponent != null )
    c.add( visualComponent, BorderLayout.CENTER );

    Component controlsComponent = player.getControlPanelComponent();

    if ( controlsComponent != null )
    c.add( controlsComponent, BorderLayout.SOUTH );

    c.doLayout();
    }
    }
    }
    }


    Continue Reading | comments

    Medical Billing system

    import java.sql.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    class Testee extends JFrame implements MouseListener
    {
    static String k[]=new String[20];
    static String j[]=new String[20];

    static JFrame jf=new JFrame("asasas");

    static TextField b=new TextField(6);

    static TextField to=new TextField(6);

    static Choice ch=new Choice();

    static TextField tf=new TextField(6);

    static TextField tootal=new TextField(6);

    static Button bt =new Button("Total");
    static Button st =new Button("Sub Total");


    static List lb1=new List();
    static List lb2=new List();
    static List lb3=new List();


    public Testee()

    {
    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection c = DriverManager.getConnection("jdbc:odbc:db1");
    Statement s = c . createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY );
    ResultSet rs = s.executeQuery("Select * from store");



    int a=0;
    while(rs.next())
    {

    j[a]=rs.getString(1);
    k[a]=rs.getString(2);
    a++;

    }


    jf.getContentPane().setLayout(new FlowLayout());

    jf.getContentPane().add(ch);
    jf.getContentPane().add(bt);
    jf.getContentPane().add(b);
    jf.getContentPane().add(tf);
    jf.getContentPane().add(to);
    jf.getContentPane().add(lb1);
    jf.getContentPane().add(lb2);
    jf.getContentPane().add(lb3);

    jf.getContentPane().add(tootal);
    jf.getContentPane().add(st);



    ch.addMouseListener(this);
    bt.addMouseListener(this);
    st.addMouseListener(this);

    for(int i=0;i{
    ch.addItem(j[i]);
    }



    }


    catch(Exception e){}
    }
    public void mouseClicked(MouseEvent e)
    {

    if(e.getSource()==ch)
    {
    //String s=ch.getSelectedItem();
    int h=ch.getSelectedIndex();
    tf.setText(k[h]);
    }
    if(e.getSource()==bt)
    { int x=Integer.parseInt(tf.getText());
    int y=Integer.parseInt(b.getText());
    int z=x*y;
    String z1=Integer.toString(z);
    to.setText(z1);
    lb1.add(ch.getSelectedItem());
    lb2.add(b.getText());
    lb3.add(z1);
    }

    if(e.getSource()==st)
    {
    for (int w=0; w<=lb3.getItemCount(); w++)
    {String c=lb3.getItem(w);
    // int g=Integer.parseInt(c));
    System.out.println(c);}
    }



    }

    public void mouseExited(MouseEvent e){}

    public void mousePressed(MouseEvent e){}

    public void mouseEntered(MouseEvent e){}

    public void mouseReleased(MouseEvent e){}

    /*public void actionPerformed(ActionEvent e)
    {
    if(e.getSource()==ch)
    {String h=ch.getSelectedItem();
    System.out.println(h);}

    }

    public void focusLost(FocusEvent e)
    {
    System.out.println("Looooost");
    }*/



    public static void main(String[] args)
    {
    Testee t=new Testee();
    jf.setVisible(true);
    }
    }


    Continue Reading | comments

    Deadlock state of a thread

    class Flintstone
    {
    int field_1;
    int field_2;
    private Object lock_1 = new int[1];
    private Object lock_2 = new int[1];

    public void fred( int value )
    {
    synchronized( lock_1 )
    {
    synchronized( lock_2 )
    {
    field_1 = 0;
    field_2 = 0;
    }
    }
    }

    public void barney( int value )
    {
    synchronized( lock_2 )
    {
    synchronized( lock_1 )
    {
    field_1 = 0;
    field_2 = 0;
    }
    }
    }
    }

    Continue Reading | comments

    Stop watch programme in java

    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;

    public class Stopwatch extends JFrame implements ActionListener, Runnable
    {
    private long startTime;
    private final static java.text.SimpleDateFormat timerFormat = new java.text.SimpleDateFormat("mm : ss.SSS");
    private final JButton startStopButton= new JButton("Start/stop");
    private Thread updater;
    private boolean isRunning= false;
    private final Runnable displayUpdater= new Runnable()
    {
    public void run()
    {
    displayElapsedTime(System.currentTimeMillis() - Stopwatch.this.startTime);
    }
    };
    public void actionPerformed(ActionEvent ae)
    {
    if(isRunning)
    {
    long elapsed= System.currentTimeMillis() - startTime;
    isRunning= false;
    try
    {
    updater.join();
    // Wait for updater to finish
    }
    catch(InterruptedException ie) {}
    displayElapsedTime(elapsed);
    // Display the end-result
    }
    else
    {
    startTime= System.currentTimeMillis();
    isRunning= true;
    updater= new Thread(this);
    updater.start();
    }
    }



    private void displayElapsedTime(long elapsedTime)
    {
    startStopButton.setText(timerFormat.format(new java.util.Date(elapsedTime)));
    }
    public void run()
    {
    try
    {
    while(isRunning)
    {
    SwingUtilities.invokeAndWait(displayUpdater);
    Thread.sleep(50);
    }
    }
    catch(java.lang.reflect.InvocationTargetException ite)
    {
    ite.printStackTrace(System.err);
    // Should never happen!
    }
    catch(InterruptedException ie) {}
    // Ignore and return!
    }
    public Stopwatch()
    {
    startStopButton.addActionListener(this);
    getContentPane().add(startStopButton);
    setSize(100,50);
    setVisible(true);
    }
    public static void main(String[] arg)
    {
    new Stopwatch().addWindowListener(new WindowAdapter()
    {
    public void windowClosing(WindowEvent e)
    {
    System.exit(0);
    }
    });
    }
    }


    Continue Reading | comments
     
    Copyright © 2011. B.Sc B.Tech MCA Ploytechnic Mini,Main Projects | Free Main Projcets Download | MCA |B.tech . All Rights Reserved
    Company Info | Contact Us | Privacy policy | Term of use | Widget | Advertise with Us | Site map
    Template Modify by Creating Website. Inpire by Darkmatter Rockettheme Proudly powered by Blogger