Php文件上传处理不会工作/文件没有出现 [英] Php file upload handling wont work/file doesnt appear
本文介绍了Php文件上传处理不会工作/文件没有出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表单来上传文件:
I have a form to upload a file:
<form enctype="multipart/form-data" method="post" action="pphoto.php">
Upload Photo: <input name="photo" type="file" required> By: <input name="by" type="text" required>
</form>
这些是表单的动作:
These is the action of the form:
<?php
if($_FILES['photo']['name'])
{
//if no errors...
if(!$_FILES['photo']['error'])
{
//now is the time to modify the future file name and validate the file
$new_file_name = strtolower($_FILES['photo']['name']); //rename file
if($_FILES['photo']['size'] > (1024000)) //can't be larger than 1 MB
{
$valid_file = false;
$message = 'Oops! Your file\'s size is to large.';
}else { $valid_file = true; }
//if the file has passed the test
if($valid_file)
{
//move it to where we want it to be
move_uploaded_file($_FILES['photo']['name'], './images/'.$new_file_name);
$message = 'Congratulations! Your file was accepted.';
}
}
//if there is an error...
else
{
//set that to be the returned message
$message = 'Ooops! Your upload triggered the following error: '.$_FILES['photo']['error'];
}
}
echo $message;
$myFile = "photos.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "<img src=\"../photos/". $_FILES['photo']['name'] ." \">";
fwrite($fh, $stringData);
fclose($fh);
?>
上传的内容比检查文件大小和对于错误,如果一切都好,则将其移动到images目录。当我上传图像时,图像目录中没有任何内容。
为什么会发生这种情况?
What happens is it uploads than checks file size and for errors, if all is good it moves it to the images directory. When i upload an image nothing appears in the image directory.
Why is this happenning?
推荐答案
_FILES [' photo'] [' name'])
{
// 如果没有错误......
if(!
_FILES['photo']['name']) { //if no errors... if(!
_FILES [' photo'] [' error'])
{
// 现在是修改未来文件名和验证文件的时间
_FILES['photo']['error']) { //now is the time to modify the future file name and validate the file
new_file_name = strtolower(
new_file_name = strtolower(
这篇关于Php文件上传处理不会工作/文件没有出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文