I'm trying to figure out how can i change the name of a file i'm about to upload.
I really prefer to changed it's name before i upload it to the server
This is the upload method at client(Android) side -
private void doFileUpload(){
File file1 = new File(pathofFile);
String urlString = "http://12.8.1.10/uploads/upload_media_test.php";
try
{
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(urlString);
FileBody bin1 = new FileBody(file1);
FileBody bin2 = new FileBody(file2);
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("uploadedfile1", bin1);
reqEntity.addPart("user", new StringBody("User"));
post.setEntity(reqEntity);
HttpResponse response = client.execute(post);
resEntity = response.getEntity();
final String response_str = EntityUtils.toString(resEntity);
if (resEntity != null) {
Log.i("RESPONSE",response_str);
runOnUiThread(new Runnable(){
public void run() {
try {
Toast.makeText(getApplicationContext(),"Upload Complete. Check the server uploads directory.", Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
catch (Exception ex){
Log.e("Debug", "error: " + ex.getMessage(), ex);
}
}
If it's possible to do it at the client side - please try to be specific as you can about how to do so.
If it's not possible, and the only option is to do that at the server side, so i adding the php code - so you could explain me what i need to change there, thanks
Php code -
$target_path1 = "uploads/";
$target_path1 = $target_path1 . basename( $_FILES['uploadedfile1']['name']);
if(move_uploaded_file($_FILES['uploadedfile1']['tmp_name'], $target_path1)) {
echo "The first file ". basename( $_FILES['uploadedfile1']['name']).
" has been uploaded.";
} else{
echo "There was an error uploading the file, please try again!";
echo "filename: " . basename( $_FILES['uploadedfile1']['name']);
echo "target_path: " .$target_path1;
}