[英]Unity3d php image upload
I have an HTML script and a PHP script to upload images on my raspberry pi server and it works.我有一个 HTML 脚本和一个 PHP 脚本来在我的树莓派服务器上上传图像并且它可以工作。 I have an app I built in unity3d for taking pictures at work and I can access my gallery in my app with the native android gallery which is free.
我有一个在 unity3d 中构建的应用程序,用于在工作时拍照,我可以使用免费的本机 Android 图库访问我的应用程序中的图库。 How do I upload the image as an image file to the php post from unity?
如何将图像作为图像文件从 unity 上传到 php 帖子? Is there a way without having to datachunck it?
有没有办法不用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>
This is the php upload code that works.这是有效的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.";
}
}
?>
I didn't have writing permission on the server folder.我没有服务器文件夹的写入权限。 I ended up
chmod 777
it which I guess is not good but it fixed the issue.我结束了
chmod 777
it 我猜这不好但它解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.