Delete files from FTP server

When we need to delete files which hosted on FTP server we need to get permissions to write. So to do that We need to connect to the FTP server.


1
2
3
4
<?php
$ftp_server = "Ftp_server_address_goes_ehre";
ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
?>


complete PHP code to delete file from FTP server.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
// connect and login to FTP server
$ftp_server = "FTP_server_address_goes_here";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");

$ftp_username = "ftp_username";
$ftp_userpass = "ftp_password";
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
//provide the file name with the path starting from default root directory
$file = "public_html/files/file.txt";

// try to delete file
if (ftp_delete($ftp_conn, $file))
  {
  $msg = "$file deleted";
  }
else
  {
  $msg = "Could not delete $file";
  }
echo $msg;
// close connection
ftp_close($ftp_conn);
?>



Delete files using PHP

Delete uploaded file in PHP using unlink() method.


We can delete files by providing the path to the file in sever. Unlink command work only if  write permissions given for the file.otherwise unlink command will get failed.


//path starting from default root directory
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<?php
$path = "photos/wallpaper.jpg"; 

if(unlink($path)){
$msg = "deleted"; 
}else{
$msg = "cannot delete"; 
}
echo $msg;
?>

Sometimes we will get warning If either the file is not exists or due to write permissions not enabled.
To ignore the warning we can suppress by adding @ symbol 


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<?php
//path starting from default root directory
$path = "photos/wallpaper.jpg"; 

if(@unlink($path)){
$msg = "deleted"; 
}else{
$msg = "cannot delete"; 
}
echo $msg;
?>


Load Data to Spinner view in Android

This is a simple example to load spinner view by an array-list.

First of all we need to create an android project. (I used eclipse)
File > New > Android Application Project


Then we need to declare an array-list in order to load values in spinner view. create array-list on Strings.xml file located under values folder.


Upload images to server from Android app

This is a simple example to upload images to hosted server from android app with help of PHP script.

First of all we need to created the PHP script which is hosted in server.

uploadImage.php


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
<?php
//path starts from the default root directory
$target_path = "images/";

$base=$_REQUEST['image'];
$name=$_REQUEST['name'];
echo $base;
echo $name;
// base64 encoded utf-8 string
$binary=base64_decode($base);
// binary, utf-8 bytes
header('Content-Type: bitmap; charset=utf-8');

$file = fopen($target_path, 'wb');
$file = fopen($name, 'wb');
fwrite($file, $binary);
fclose($file);

copy($name,$target_path.$name);
?>

Then create an Android Application Project using eclipse or any other IDE.











After creating new android project open the activity_main.xml.



update the activity_main.xml with following code.


Upload Images to server using PHP

Simple example to upload images to server with PHP.

When we need to upload images/ files to server file manager(hosted in local server or hosted website) it is easy to create a PHP file using Dreamweaver. 
Using Dreamweaver
1. Go to File > New  and select PHP
2.Then add Following form anywhere between <body></body> tag.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
<table bgcolor="#009900" align="center" width="300" border="1" cellspacing="0" cellpadding="10">
 
    <td class="tableheading">Image</td>
    <td><input type="file" name="fileupload" accept="image/jpeg" required/></td>
  </tr>
  <tr height="40" class="regTableTag1">
    <td>&nbsp;</td>
    <td><input type="submit" name="submit" value="PUSH" />
    </td>
  </tr>
 </table>
</form>

How To Download Data from server in Android

How To Download Data from server in Android with php & MySql

Here I'm used php script to download data stored in MySQL database;

Create table in MySql

1
2
3
4
5
CREATE TABLE users(
id int,
name Text,
email Text
);

Table insert statement for users


1
INSERT INTO users(id,name,email) VALUES (1,'user1','user1@mail.com')

In order to download data from server we have to use JSON output in server.
myScript.php