I'm starting on android and I still can not react very well to the errors, I'm working on an application to capture images from the camera and upload them to the server everything works perfect but at the time of pressing the button upload only stores the name of the image in my table and does not upload the image to the folder
the php files are
upload.php
<?PHP
$ruta = "imagenes/" .basename($_FILES['fotoUp']['name']);
if(move_uploaded_file($_FILES['fotoUp']['tmp_name'], $ruta))
chmod ("uploads/".basename( $_FILES['fotoUp']['name']), 0644);
?>
insertImage.php
<?PHP
$hostname_localhost ="localhost";
$database_localhost ="basededatos";
$username_localhost ="root";
$password_localhost ="";
$localhost = mysql_connect($hostname_localhost,$username_localhost,$password_localhost)
or
trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_localhost, $localhost);
$imagen=$_POST['imagen'];
$query_search = "insert into imagenes(imagen) values ('".$imagen."')";
$query_exec = mysql_query($query_search) or die(mysql_error());
mysql_close($localhost);
?>
the android method
private void uploadFoto(String imag) {
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpPost httppost = new HttpPost("/upload.php");
MultipartEntity mpEntity = new MultipartEntity();
ContentBody foto = new FileBody(file, "image/jpeg");
mpEntity.addPart("fotoUp", foto);
httppost.setEntity(mpEntity);
try {
httpclient.execute(httppost);
httpclient.getConnectionManager().shutdown();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private boolean onInsert(){
HttpClient httpclient;
List<NameValuePair> nameValuePairs;
HttpPost httppost;
httpclient=new DefaultHttpClient();
httppost= new HttpPost("/insertImagen.php");
nameValuePairs = new ArrayList<NameValuePair>(1);
boolean imagen = nameValuePairs.add(new BasicNameValuePair("imagen", nombreImagen.getText().toString().trim() + ".jpg"));
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httpclient.execute(httppost);
return true;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return false;
}