so i want to have it set up so when the user uploads there video there email and product key code go with it so in the PHP i can create a new directory with there email. Then name the video as the product key code. I can upload the video fine if i remove the code trying to upload the string.
Android code:
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 code:
<?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);
}
?>
If theres a different way to do it or theres nothing wrong please tell me! thank you!