2017-05-29 3 views
-1

In dem Projekt arbeite ich gerade für eine Firma Ich muss ein Bild an eine .php auf einem Server senden, der es in einem Ordner speichert und dann die URL so zurücksendet Ich kann es auf einem Tisch von einem DB speichern. Das Unternehmen möchte, dass ich das rohe Bild sende, anstatt es in base64 zu konvertieren, sende es und dekodiere es in der Datei .phpBild direkt an .PHP senden, ohne Base64 zu verwenden

Meine Frage ist, ist das möglich? und wenn ja, wie kann ich es tun?

Danke für die Hilfe.

+0

Ich bin mir ziemlich sicher, wenn Sie hier in SO eine Suche durchführen, finden Sie viele ähnliche Antworten – RiggsFolly

Antwort

0

Ja, es ist möglich.

Prüfen Sie die php.ini und stellen Sie sicher, dass diese Linie ist wie folgt:

file_uploads = On 

HTML-Formular erstellen:

<!DOCTYPE html> 
<html> 
<body> 

<form action="upload.php" method="post" enctype="multipart/form-data"> 
    Select image to upload: 
    <input type="file" name="fileToUpload" id="fileToUpload"> 
    <input type="submit" value="Upload Image" name="submit"> 
</form> 

</body> 
</html> 

Und creat upload.php Datei:

<?php 
$target_dir = "uploads/"; 
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); 
$uploadOk = 1; 
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); 
// Check if image file is a actual image or fake image 
if(isset($_POST["submit"])) { 
    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); 
    if($check !== false) { 
     echo "File is an image - " . $check["mime"] . "."; 
     $uploadOk = 1; 
    } else { 
     echo "File is not an image."; 
     $uploadOk = 0; 
    } 
} 
// Check if file already exists 
if (file_exists($target_file)) { 
    echo "Sorry, file already exists."; 
    $uploadOk = 0; 
} 
// Check file size 
if ($_FILES["fileToUpload"]["size"] > 500000) { 
    echo "Sorry, your file is too large."; 
    $uploadOk = 0; 
} 
// Allow certain file formats 
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" 
&& $imageFileType != "gif") { 
    echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; 
    $uploadOk = 0; 
} 
// Check if $uploadOk is set to 0 by an error 
if ($uploadOk == 0) { 
    echo "Sorry, your file was not uploaded."; 
// if everything is ok, try to upload file 
} else { 
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { 
    echo "The file ". basename($_FILES["fileToUpload"]["name"]). " has been  uploaded."; 
    } else { 
     echo "Sorry, there was an error uploading your file."; 
    } 
} 
?> 

Um sicherzustellen, dass alles funktioniert, erstellen Sie einen Ordner mit dem Namen uploads und stellen Sie sicher, dass die Dateiberechtigungen und die Eigentümerschaft in Ordnung sind.

Ich hoffe, es hilft Ihnen.

+0

Beachten Sie, dass dieser Code stammt aus [w3schools] (https://www.w3schools.com/php/php_file_upload.asp) –

Verwandte Themen