B4A Library Upload file with php

Version 1.0

Requirements:
1- B4A 3.x
2- Copy the UploadFilePhp.xml and UploadFilePhp.jar to your additional libraries directory.

eng

Sorry for my English I translate with google!
This library is used to upload files to the web server through php page.
B4A sends the file to the php page that saves them in the server folder!
ita
Scusate il mio inglese traduco con google!
questa libreria serve a uplodare file nel web server attraverso pagina php.
B4A invia i file alla pagina php che li salva nella cartella del server!


eng
simple php page to be included in your server!
ita
semplice pagina php da inserire nel vostro server!

problem 3g
I only have problems with slow connections with Android 2.3.0



B4X:
Eng
Be careful when you do the tests do not send the same file, change it generates an error if no "why the file on the server can not be written when you are opening!"
Ita
Attenzione quando fate le prove non inviate lo stesso file,cambiatelo se no genera un errore "motivo il file sul server non può essere scritto quando è apperto!"

Attention this code and sample files !!!!
security change you as you please do not take any responsibility!

ITA
Attenzione questo codice e file di esempio!!!!
per la sicurezza modificarlo voi a vostro piacimento non mi prendo alcuna responsabilità!



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";
    }
?>
B4X:
Dim Up As UploadFilePhp

Up.Initialize("Up")
Up.doFileUpload( ProgressBar1,Label1,Path_Phone_Image & name_image,Url_Php_Page)
 

Attachments

  • UploadfilePhp.zip
    9.7 KB · Views: 1,700
Last edited:

Douglas Farias

Expert
Licensed User
Longtime User
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://74.63.193.55/clickfight/merda.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.DirAssets & "/"  'OR  "/sdcard/
Dim name_image As String
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.DirAssets & "/"  '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


error log

B4X:
LogCat connected to: B4A-Bridge: motorola XT1033-359321054369100
--------- beginning of /dev/log/main
libcore.io.ErrnoException: recvfrom failed: ECONNRESET (Connection reset by peer)
Connected to B4A-Bridge (Wifi)
Installing file.
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:b4a.Spinter.upload
Copying updated assets files (1)
** Activity (main) Create, isFirst = true **
B4A log: Initialize UploadFile library
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
B4A log: Exception!
B4A log: Disconnect!
false \ 
false \ 
B4A log: End Upload
false \ 
** Activity (main) Pause, UserClosed = true **
** Activity (main) Resume **
(Intent) Intent { act=android.intent.action.MAIN flg=0x20000000 cmp=b4a.Spinter.upload/.main }
no extras
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = true **
B4A log: Initialize UploadFile library
** Activity (main) Resume **
B4A log: Exception!
B4A log: Disconnect!
false \ 
false \ 
B4A log: End Upload
false \ 
** Activity (main) Pause, UserClosed = true **
** Activity (main) Resume **
(Intent) Intent { act=android.intent.action.MAIN flg=0x20000000 cmp=b4a.Spinter.upload/.main }
no extras
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = true **
B4A log: Initialize UploadFile library
** Activity (main) Resume **
B4A log: Exception!
B4A log: Disconnect!
false \ 
false \ 
B4A log: End Upload
false \ 
B4A log: Exception!
B4A log: Disconnect!
false \ 
false \ 
B4A log: End Upload
false \ 
B4A log: Exception!
B4A log: Disconnect!
false \ 
false \ 
B4A log: End Upload
false \ 
B4A log: Exception!
B4A log: Disconnect!
false \ 
false \ 
B4A log: End Upload
false \ 
B4A log: Exception!
B4A log: Disconnect!
false \ 
false \ 
B4A log: End Upload
false \ 
B4A log: Exception!
B4A log: Disconnect!
false \ 
false \ 
B4A log: End Upload
false \ 
B4A log: Exception!
B4A log: Disconnect!
false \ 
false \ 
B4A log: End Upload
false \ 
B4A log: Exception!
B4A log: Disconnect!
false \ 
false \ 
B4A log: End Upload
false \ 
** Activity (main) Pause, UserClosed = true **
** Activity (main) Resume **
(Intent) Intent { act=android.intent.action.MAIN flg=0x20000000 cmp=b4a.Spinter.upload/.main }
no extras
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = true **
B4A log: Initialize UploadFile library
** Activity (main) Resume **
B4A log: Exception!
B4A log: Disconnect!
false \ 
false \ 
B4A log: End Upload
false \ 
B4A log: Exception!
B4A log: Disconnect!
false \ 
false \ 
B4A log: End Upload
false \ 
B4A log: Exception!
B4A log: Disconnect!
false \ 
false \ 
B4A log: End Upload
false \ 
B4A log: Exception!
B4A log: Disconnect!
false \ 
false \ 
B4A log: End Upload
false \ 
B4A log: Exception!
B4A log: Disconnect!
false \ 
false \ 
B4A log: End Upload
false \ 
B4A log: Exception!
B4A log: Disconnect!
false \ 
false \ 
B4A log: End Upload
false \ 
B4A log: Exception!
B4A log: Disconnect!
false \ 
false \ 
B4A log: End Upload
false \ 
B4A log: Exception!
B4A log: Disconnect!
false \ 
false \ 
B4A log: End Upload
false \ 
B4A log: Exception!
B4A log: Disconnect!
false \ 
false \ 
B4A log: End Upload
false \ 
B4A log: Exception!
B4A log: Disconnect!
false \ 
false \ 
B4A log: End Upload
false \
 

Douglas Farias

Expert
Licensed User
Longtime User
i m fixed now ty
this error is because my image is on assets
i change assets to dirroot and work *-*

B4X:
Dim Path_Phone_Image As String
Path_Phone_Image = File.DirRootExternal & "/"  'OR  "/sdcard/
Dim name_image As String
name_image="1.jpg"
Up.doFileUpload( ProgressBar1,Label1,Path_Phone_Image & name_image,Url_Php_Page )   
End Sub
 

Douglas Farias

Expert
Licensed User
Longtime User
yes working fine i m using your lib ty man *-*
 

Douglas Farias

Expert
Licensed User
Longtime User
spinter how can i fix this error

when i upload image 1 on galaxy devices is ok
no problem when i upload image2 give a problem exeption

image 3 go fine

again image 4 problem

firsth upload ok second fail every time can you help me on this ?

i think need make a up.finish

and start this again when you go send 2° image

can you help me on this ?
 

Spinter

Active Member
Licensed User
Longtime User
looks at the problem and allowed, you should handle the upload is finished when one from the other!
If you let them all go along with the poor and allowed the library should be in force for exeption.
however, I have to check these days!
 

Douglas Farias

Expert
Licensed User
Longtime User
is not same but it dont is your lib problem dont wory :)
is from the galaxy cameras i go try fix this i need help only with upload 2 files *-*

ty for u lib man
 

Douglas Farias

Expert
Licensed User
Longtime User
edit* the problem to upload 2° time is on all galaxy devices, on moto G dont have problem u can upload a file
later another file , infinity files

on galaxys have problem you upload later cant upload another file
nothings happens o_O

i think need add finish event when the upload is finish finish the lib too
later to upload again you just load again the lib

routine start-finish-start


and another segestion is add multiple files upload

like 1.jpg 2.jpg at same time *-*
 
Last edited:

Spinter

Active Member
Licensed User
Longtime User
view: the web page when the file and sends you shipped fully success! ok?
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";
    }
?>





it checks if the file is received in the event! sub Upl_sendFile

B4X:
Sub Upl_sendFile (value AsString)


Label1.Text=value


End Sub
 

Luis Sol

Member
Licensed User
Longtime User
Hello Spinter,

i'm having problems with your library on android 2.3

I am connecting to an SSL service that gives this error

[Thu May 29 16:48:54 2014] [debug] ssl_engine_io.c(1892): +-------------------------------------------------------------------------+
[Thu May 29 16:48:54 2014] [debug] ssl_engine_kernel.c(1876): OpenSSL: Loop: SSLv3 read finished A
[Thu May 29 16:48:54 2014] [debug] ssl_engine_kernel.c(1876): OpenSSL: Loop: SSLv3 write session ticket A
[Thu May 29 16:48:54 2014] [debug] ssl_engine_kernel.c(1876): OpenSSL: Loop: SSLv3 write change cipher spec A
[Thu May 29 16:48:54 2014] [debug] ssl_engine_kernel.c(1876): OpenSSL: Loop: SSLv3 write finished A
[Thu May 29 16:48:54 2014] [debug] ssl_engine_kernel.c(1876): OpenSSL: Loop: SSLv3 flush data
[Thu May 29 16:48:54 2014] [debug] ssl_engine_kernel.c(1872): OpenSSL: Handshake: done
[Thu May 29 16:48:54 2014] [info] Connection: Client IP: 201.141.116.8, Protocol: TLSv1, Cipher: RC4-MD5 (128/128 bits)
[Thu May 29 16:48:54 2014] [debug] ssl_engine_io.c(1925): OpenSSL: I/O error, 5 bytes expected to read on BIO#7f39a3f64260 [mem: 7f39a3f6b8f3]
[Thu May 29 16:48:54 2014] [info] [client 201.141.116.8] (70014)End of file found: SSL input filter read failed.
[Thu May 29 16:48:54 2014] [debug] mod_dumpio.c(127): mod_dumpio: dumpio_in - 70014
[Thu May 29 16:48:54 2014] [debug] mod_dumpio.c(142): mod_dumpio: dumpio_out
[Thu May 29 16:48:54 2014] [debug] mod_dumpio.c(55): mod_dumpio: dumpio_out (metadata-FLUSH): 0 bytes
[Thu May 29 16:48:54 2014] [debug] mod_dumpio.c(55): mod_dumpio: dumpio_out (metadata-EOC): 0 bytes


i recently modified my APP to allow for insecure SSL certificates

sincerely

Luis
 

Douglas Farias

Expert
Licensed User
Longtime User
B4X:
view: the web page when the file and sends you shipped fully success! ok?
]

at first time upload sucess ok next time give exception on the app not on the web

i think need kill the up.finish

and start this again later

up.initializate
 

Spinter

Active Member
Licensed User
Longtime User
Hello Spinter,

i'm having problems with your library on android 2.3

Luis


I only have problems with slow connections with Android 2.3.0

I tried and tried even asking for help, and they told me that it is a problem of Android 2.2 .2.3

if you try to WI Fi should work right?
 
Last edited:

Spinter

Active Member
Licensed User
Longtime User
B4X:
view: the web page when the file and sends you shipped fully success! ok?
]

at first time upload sucess ok next time give exception on the app not on the web

i think need kill the up.finish

and start this again later

up.initializate

the response from the server can not make it static, because for different applications need dynamic!

to manage sucess I create a php page that you can not change! you okay?
At this point it is best that you manage yourself that you can edit as you wish!
 

Douglas Farias

Expert
Licensed User
Longtime User
ok i m using your page

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";
    }
?>

http://74.63.193.55/clickfight/teste/recebe.php


its realy problem with samsung galaxy devices *-*

on moto g i can upload again and again again etc

galaxy s3 - galaxy star etc etc only one time
upload one time u need close the app and open again to upload another file *-*


i m using your sample code and php page with no modifications to test this
realy is only on the galaxy devices
 
Top