繁体   English   中英

Unity3d php图片上传

[英]Unity3d php image upload

我有一个 HTML 脚本和一个 PHP 脚本来在我的树莓派服务器上上传图像并且它可以工作。 我有一个在 unity3d 中构建的应用程序,用于在工作时拍照,我可以使用免费的本机 Android 图库访问我的应用程序中的图库。 如何将图像作为图像文件从 unity 上传到 php 帖子? 有没有办法不用datachunck呢?

<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>

这是有效的php上传代码。

header('Content-type: text/plain');

$target_dir = "";
$target_file = base64_encode($target_dir . basename($_FILES["fileToUpload"]["name"]));
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));

// Check if image file is a actual image or fake image
if(isset($_POST["theFile"])) {
 $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
 if($check !== false) {
   $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"] > 500000000) {
 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 "Copy the link below and add to Website Address or Picture Menu Address: \r\n"."adatouch.hopto.org/". htmlspecialchars( basename( $_FILES["fileToUpload"]["name"]));
 } else {
   echo "Sorry, there was an error uploading your file.";
 }
}
?>

我没有服务器文件夹的写入权限。 我结束了chmod 777 it 我猜这不好但它解决了这个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM