我需要为视频上传文件。我能够用PHP上传视频,但我需要一种方法来显示文件上传进度与PHP,当它100%上传我应该显示成功消息。
目前使用ajax完成文件上传。
问题是,我尝试使用is_uploaded_file方法,但此代码在上传文件之前运行,并且始终返回false。 http://us1.php.net/is_uploaded_file
我应该使用任何后台程序吗?
<?php
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
echo "File ". $_FILES['userfile']['name'] ." uploaded successfully.\n";
echo "Displaying contents\n";
readfile($_FILES['userfile']['tmp_name']);
} else {
echo "Possible file upload attack: ";
echo "filename '". $_FILES['userfile']['tmp_name'] . "'.";
}
?>
答案 0 :(得分:1)
is_uploaded_file()函数将检查您可以上传的文件。
使用move_uploaded_file()函数代替该函数。
参考:http://php.net/manual/en/function.move-uploaded-file.php
if (is_uploaded_file($_FILES['userfile']['tmp_name']) && move_uploaded_file($_FILES['userfile']['tmp_name'], "put here target directory path")) {
echo "File ". $_FILES['userfile']['name'] ." uploaded successfully.\n";
echo "Displaying contents\n";
readfile($_FILES['userfile']['tmp_name']);
} else {
echo "Possible file upload attack: ";
echo "filename '". $_FILES['userfile']['tmp_name'] . "'.";
}