Code – die besten Beiträge

PHP Upload funktioniert auf PC aber nicht aufm Handy?

Hallo,

dieser Code funktioniert nicht auf Handy aber auf dem PC, hat wer tipps?

Clientseite (JavaScript):
<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <script src="https://code.jquery.com/jquery-3.7.1.js" integrity="sha256-eKhayi8LEQwp4NKxN+CfCh+3qOVUtJn3QNZ0TciWLP4=" crossorigin="anonymous"></script></head>
<body>
<form id="fileUploadForm" enctype="multipart/form-data">
    <input type="file" name="file" id="fileInput" required>
    <button type="button" id="uploadButton">Hochladen</button>
</form>


<script>
    $(document).ready(function(){
        $('#uploadButton').on('click touchend', function(){
            var formData = new FormData($('#fileUploadForm')[0]);
            $.ajax({
                url: 'https://sub-upload.main.de/upload.php',
                type: 'POST',
                data: formData,
                processData: false,
                contentType: false,
                success: function(response){
                    console.log(response);
                    alert(response);
                },
                error: function(xhr, status, error){
                    alert(error + xhr.status);
                }
            });
        });
    });


</script>
</body>
</html>
Serverseite (upload.php):
<?php
$targetDirectory = '../uploads/';
header("Access-Control-Allow-Origin: https://sub.main.de");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Allow-Headers: Content-Type");
if (!file_exists($targetDirectory)) {
    mkdir($targetDirectory, 0777, true);
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
    $targetFile = $targetDirectory . basename($_FILES['file']['name']);
    if (move_uploaded_file($_FILES['file']['tmp_name'], $targetFile)) {
        echo 'Die Datei wurde erfolgreich hochgeladen.';
    } else {
        echo 'Beim Hochladen der Datei ist ein Fehler aufgetreten.';
    }
} else {
    echo 'Keine Datei zum Hochladen gefunden.';
}
?>
HTML, Webseite, JavaScript, HTML5, Code, Datenbank, JQuery, MySQL, PHP, Programmiersprache, Webdesign, Webentwicklung

Java: Methode wird sehr wahrscheinlich nicht aufgerufen?

Mein Programm lässt sich ohne jegliche Fehlermeldungen, etc. kompilieren und ausführen. Beim Ausführen des Codes stoppt es ohne einen von mir ersichtlichen Grund, wenn es die Methode karteout() ausführen soll. Es zeigt mir, wo es eigentlich einen Namen einer Spielkarte anzeigen sollte, einfach eine leere Zeile an, in die ich nichts eingeben kann.

Mein Code:

Main.java:

public class Main {
  public static void main(String[] args) {
    Kartendeck karten = new Kartendeck();
    karten.kartendeck();
    Player pturn = new Player();
    pturn.player();
  }
}

Kartendeck.java:

import java.util.Random;

public class Kartendeck {
  private int counter1;
  private int cardid;
  private int[] cards = new int[52];
  private int karte;
  private int zs1;

  public void kartendeck() {
    counter1 = -1;

    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 13; j++) {
        i++;
        j++;
        cardid = 100 * i + j;
        counter1++;
        i--;
        j--;
        cards[counter1] = cardid;
      }
    }
  }

  public void karteout() {
    Random random = new Random();
    loopkarte: while (true) {
      karte = random.nextInt(52);
      zs1 = cards[karte];

      if (cards[karte] != 0) {
        cards[karte] = 0;
        break loopkarte;
      }
    }

    if (zs1 % 100 == 1) {
      System.out.print("Ace ");
    }
    else if (zs1 % 100 == 2) {
      System.out.print("2 ");
    }
    else if (zs1 % 100 == 3) {
      System.out.print("3 ");
    }
    else if (zs1 % 100 == 4) {
      System.out.print("4 ");
    }
    else if (zs1 % 100 == 5) {
      System.out.print("5 ");
    }
    else if (zs1 % 100 == 6) {
      System.out.print("6 ");
    }
    else if (zs1 % 100 == 7) {
      System.out.print("7 ");
    }
    else if (zs1 % 100 == 8) {
      System.out.print("8 ");
    }
    else if (zs1 % 100 == 9) {
      System.out.print("9 ");
    }
    else if (zs1 % 100 == 10) {
      System.out.print("10 ");
    }
    else if (zs1 % 100 == 11) {
      System.out.print("Jack ");
    }
    else if (zs1 % 100 == 12) {
      System.out.print("Queen ");
    }
    else if (zs1 % 100 == 13) {
      System.out.print("King ");
    }
    else {
      System.out.print("");
    }

    if ((zs1 - zs1 % 100) / 100 == 1) {
      System.out.println("of Spades");
    }
    else if ((zs1 - zs1 % 100) / 100 == 2) {
      System.out.println("of Hearts");
    }
    else if ((zs1 - zs1 % 100) / 100 == 3) {
      System.out.println("of Clubs");
    }
    else if ((zs1 - zs1 % 100) / 100 == 4) {
      System.out.println("of Diamonds");
    }
    else {
      System.out.print("");
    }
  }
}

Player.java:

import java.util.Scanner;

public class Player {
  private String userinput;

  public void player() {
    Scanner scan = new Scanner(System.in);
    Kartendeck karten = new Kartendeck();
    System.out.println("CPU's up:");
    karten.karteout();
    System.out.println("Deine Startkarten:");
    karten.karteout();
    karten.karteout();

    loopturn: while (true) {
      System.out.println("Was möchtest du machen?");
      System.out.println("--> Hit");
      System.out.println("--> Stay");
      userinput = scan.nextLine();

      loopuser: while (true) {
        if (userinput.equals("Hit")) {
          karten.karteout();
          break loopuser;
        }
        else if (userinput.equals("Stay")) {
          break loopturn;
        }
        else {
          System.out.println("Diese Funktion ist nicht verfügbar!");
        }
      }
    }
  }
}

Ich hoffe, mir kann jemand helfen und vielen Dank im Voraus.

Java, Code

Warum kann ich meinen HTML- Code nicht mit meinem Python- Code verbinden?

Hallo,

ich wollte meinen Python- Code mit meinem HTML- Code verbinden, damit, wenn mein Wake- Word "Luna" erkannt wurde, ein div in der Datei index.html seine Farbe ändert. Hier ist der Code:

Python:

from flask import Flask, render_template
from flask_socketio import SocketIO, emit

app = Flask(__name__)
app.config['SECRET_KEY'] = 'luna_secret1984773249523'
socketio = SocketIO(app)


@socketio.on('connect')
def handle_connect():
    emit('message', {'data': 'Connected'})


@socketio.on('start_listening')
def start_listening():
    if detect_wake_word():
        emit('color_change', {'color': 'red'})


@app.route('/')
def index():
    return render_template('output.html')

HTML /CSS:

... #color_div {
    width: 100%;
    height: 100%;
    position: absolute;
    background-color: green;
}    
</style>
</head>
<body>
<div id="color_div"></div>

JavaScript:

... // FLASK
        var socket = io();

        socket.on('connect', function() {
            socket.emit('start_listening');
        });

        socket.on('color_change', function(msg) {
            document.getElementById('color_div').style.backgroundColor = msg.color;
        });
</script>
</body>
</html>
    """
    with open("output.html", "w") as html_file:
        html_file.write(html_content)

    return "output.html"

Wenn ich den Code aber ausführe und "Luna" sage, ändert der Div nicht seine Farbe. Woran liegt das?

Freundliche Grüsse

HTML, Webseite, CSS, JavaScript, HTML5, Code, Programmiersprache, Python, Webentwicklung, Frontend, Python 3, Flask

Meistgelesene Beiträge zum Thema Code