我正在使用下面的代码来访问 html 5 相机并将图像上传到服务器。
HTML 代码
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="image" accept="image/*" capture>
<input type="submit" value="Upload">
</form>
上传.php代码
<?php
$target_path = "upload/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
问题是当我测试代码时,它显示“上传文件时出错,请重试!” . 谁能帮我找出问题所在?
下面的代码对我来说正常工作。
HTML 代码:
<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
PHP代码与上面相同。