böylece kullanıcı orada yüklediğinde oraya e-posta ve ürün anahtar kodu yüklediğinde kurulum yapmak istiyorum böylece PHP'de e-posta ile yeni bir dizin oluşturabilirim . Ardından videoyu ürün anahtar kodu olarak adlandırın. Diziyi yüklemeye çalışırken kodu kaldırırsam videoyu iyi yükleyebilirim.
Android kodu:
try{
FileInputStream fileInputStream = new FileInputStream(sourceFile);
URL url = new URL(UploadVideo_URL);
conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("ENCTYPE", "multipart/form-data");
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
conn.setRequestProperty("myFile", selectedPath);
dos = new DataOutputStream(conn.getOutputStream());
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data; name=\"" + ProductOwnerEmail + "\"" + lineEnd);
dos.writeBytes(lineEnd);
dos.write(ProductOwnerEmail.getBytes());
dos.writeBytes(lineEnd);
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data; name=\"" + ProductKeyCode + "\"" + lineEnd);
dos.writeBytes(lineEnd);
dos.write(ProductOwnerEmail.getBytes());
dos.writeBytes(lineEnd);
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data; name=\"myFile\";filename=\"" + selectedPath + "\"" + lineEnd);
dos.writeBytes(lineEnd);
bytesAvailable = fileInputStream.available();
Log.i("Huzza", "Initial .available : " + bytesAvailable);
bufferSize = Math.min(bytesAvailable, maxBufferSize);
buffer = new byte[bufferSize];
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
while (bytesRead > 0) {
dos.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}
dos.writeBytes(lineEnd);
dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
serverResponseCode = conn.getResponseCode();
fileInputStream.close();
dos.flush();
dos.close();
} catch (Exception e) {
e.printStackTrace();
return "Product upload failed";
}
PHP kodu:
<?php
$ProductOwnerEmail = $_POST['ProductOwnerEmail'];
$ProductKeyCode = $_POST['ProductKeyCode'];
$NewDirectory = "/var/www/html/ProductVideos/" . $ProductOwnerEmail;
mkdir($NewDirectory, 0777, true);
if($_SERVER['REQUEST_METHOD']=='POST'){
$file_name = $_FILES['myFile']['name'];
$file_size = $_FILES['myFile']['size'];
$file_type = $_FILES['myFile']['type'];
$temp_name = $_FILES['myFile']['tmp_name'];
$location = "/var/www/html/ProductVideos/$ProductOwnerEmail/" . $ProductKeyCode;
move_uploaded_file($temp_name, $location);
}
?>
gidecekseniz farklı şekilde yapmak ya da yanlış hiçbir şey yok etmek ise söyle lütfen! teşekkür ederim!
[bu bir denediniz mi?] (Http://stackoverflow.com/a/34127008/1318946) –
hayır ben değil aslında var! –