سلام
من همه مراحل را رفتم و با اين دستورات هم فايل را به سرور ارسال مي كنم ولي خطا مي دهد
MultipartUtility multipart = null;
try {
multipart = new MultipartUtility("http://www.MYSITE.com/index.php?app/send_file", "UTF-8");
multipart.addFilePart("fileUpload", new File(uploadFile1.getPath()));
} catch (IOException e) {
e.printStackTrace();
}
اين هم خطا:
FATAL EXCEPTION: main
android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNe twork(StrictMode.java:1117)
at java.net.InetAddress.lookupHostByName(InetAddress. java:385)
at java.net.InetAddress.getAllByNameImpl(InetAddress. java:236)
at java.net.InetAddress.getAllByName(InetAddress.java :214)
at libcore.net.http.HttpConnection.<init>(HttpConnect ion.java:70)
at libcore.net.http.HttpConnection.<init>(HttpConnect ion.java:50)
at libcore.net.http.HttpConnection$Address.connect(Ht tpConnection.java:340)
at libcore.net.http.HttpConnectionPool.get(HttpConnec tionPool.java:87)
at libcore.net.http.HttpConnection.connect(HttpConnec tion.java:128)
at libcore.net.http.HttpEngine.openSocketConnection(H ttpEngine.java:316)
at libcore.net.http.HttpEngine.connect(HttpEngine.jav a:311)
at libcore.net.http.HttpEngine.sendSocketRequest(Http Engine.java:290)
at libcore.net.http.HttpEngine.sendRequest(HttpEngine .java:240)
at libcore.net.http.HttpURLConnectionImpl.connect(Htt pURLConnectionImpl.java:81)
at libcore.net.http.HttpURLConnectionImpl.getOutputSt ream(HttpURLConnectionImpl.java:197)
at ghazalina.sytama.MultipartUtility.<init>(Multipart Utility.java:55)
at ghazalina.sytama.Evaluation$1$2.onClick(Evaluation .java:318)
at com.android.internal.app.AlertController$ButtonHan dler.handleMessage(AlertController.java:166)
at android.os.Handler.dispatchMessage(Handler.java:99 )
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.jav a:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:560)
at dalvik.system.NativeStart.main(Native Method)
نميدونم كد سمت سرور مشكل داره يا اين كدي كه نوشته ام
كد بخش سرور
function send_file(){
$allowed = array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'text/plain','application/pdf','image/jpeg','image/gif','image/tiff','application/msword',
'text/html','image/png','application/msword','application/vnd.openxmlformats-officedocument.wordprocessingml.document');
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $_FILES['fileUpload']['tmp_name']);
$size = filesize($_FILES['fileUpload']['tmp_name']);
finfo_close($finfo);
if((in_array($mime,$allowed) && $size<500000 && $_FILES['fileUpload']['tmp_name'] != "") || $_FILES['fileUpload']['tmp_name'] == "" ) {
if($_FILES['fileUpload']['tmp_name'] != ""){
$type = explode(".",$_FILES['fileUpload']['name']);
$filename = 'uploads/pp'.rand(111111111, 999999999).'.'.$type[1];
move_uploaded_file($_FILES['fileUpload']['tmp_name'], $filename);
}
}
}