Hi all
I tried to use UploadFilePhp library to upload a file to local host server, but always I get (fail).
this is the php file:
I tried to use UploadFilePhp library to upload a file to local host server, but always I get (fail).
B4X:
#Region Project Attributes
#ApplicationLabel: B4A Example Upload
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim Up As UploadFilePhp
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private Button1 As Button
Private Button2 As Button
Private Label1 As Label
Private Label2 As Label
Private ProgressBar1 As ProgressBar
Dim Url_Php_Page As String
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Layout_upload")
Url_Php_Page="http://192.168.8.4/upload_file.php"
If FirstTime Then
Up.B4A_log=True
Up.Initialize("Up")
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean
If KeyCode=KeyCodes.KEYCODE_BACK Then
Dim domanda2 As Int
domanda2 = Msgbox2("Vuoi Uscire?","Avviso","Yes","","No",Null)
If domanda2 = DialogResponse.POSITIVE Then
Up.UploadKill
ExitApplication
Else If domanda2 = DialogResponse.NEGATIVE Then
Return True
End If
End If
Return True
End Sub
Sub Up_statusUpload (value As String)
'Label1.Text=value
'Label2.Text=value
End Sub
Sub Up_sendFile (value As String)
Label2.Text=value
End Sub
Sub Up_statusVISIBLE (onoff As Boolean,value As String)
Log(onoff&" \ "&value)
End Sub
Sub Button1_Click
Label1.Text=""
Label2.Text=""
Dim Path_Phone_Image As String
Path_Phone_Image = File.DirInternal & "/" 'OR "/sdcard/
Dim name_image As String
File.Copy(File.DirAssets,"1.jpg",File.DirInternal,"1.jpg")
name_image="1.jpg"
Up.doFileUpload( ProgressBar1,Label1,Path_Phone_Image & name_image,Url_Php_Page)
End Sub
Sub Button2_Click
Label1.Text=""
Label2.Text=""
Dim Path_Phone_Image As String
Path_Phone_Image = File.DirInternal & "/" 'OR "/sdcard/
Dim name_image As String
name_image="1.jpg"
Up.doFileUpload( Null,Null,Path_Phone_Image & name_image,Url_Php_Page)
End Sub
this is the php file:
B4X:
<?php
$file_path = "uploads/";
$file_path = $file_path . basename( $_FILES['uploaded_file']['name']);
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $file_path)) {
echo "success";
} else{
echo "fail";
}
?>