我正在尝试将图片上传到我的网站,但它似乎不起作用,而是打印一长串文字,包括无法识别的字符。
PHP代码:
$target_file = "path/from/webserver/Users/".$_SESSION['user']['user_code']."/background.jpg";
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
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;
}
}
if(!empty($_FILES["fileToUpload"])) {
// Check file size
if ($_FILES["fileToUpload"]["size"] > 10485760) {
echo "Sorry, your file is too large.";
$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)) {
$image = imagecreatefromjpeg($target_file);
unlink($target_file);
imagejpeg($image,NULL,60);
header("Location: profile.php");
} else {
echo "Sorry, there was an error uploading your file.";
}
}
}
我的HTML表单是:
$t
变量仅供语言正常使用
<form action="background.php" method="post" enctype="multipart/form-data" style="margin-top:20px;">
<div class="fileUpload btn btn-primary" style="margin-top:-1px">
<span><div class="glyphicon glyphicon-picture"></div> <?php echo $t['change_input_select'];?></span>
<input type="file" name="fileToUpload" id="fileToUpload" class="upload" accept="image/*" />
</div>
<input type="submit" value="<?php echo $t['change_input_submit'];?>" name="submit" class="btn btn-success" style="margin-top:-10px">
<a class="btn btn-danger" href="edit_account.php" style="margin-top:-10px"><?php echo $t['change_input_abort'];?></a>
</form>
也许你可以给我一些关于如何让它更可靠的提示。