我正在努力为我的网站创建音频文件上传表单。我觉得上传部分工作正常,但当我试一试并提交上传时,它会转到正确的php页面,但屏幕全是白色的,没有任何内容。
我的目标是将上传的音频文件移到我服务器上的上传目录中。
我有以下代码:
<!DOCTYPE html>
<html>
<head>
<title>File Upload Form</title>
</head>
<body>
<form action="gettfile.php" method="post" enctype="multipart/form-data">
<input type="file" name="uploadFile" id="uploadFile">
<input type="submit" value="Upload File" name="submit">
<p> testen </p>
</form>
</body>
</html>
和php页面:
<?php
$uploads_dir = 'uploads';
$tmp_name = $_FILES["uploadFile"]["tmp_name"][$key];
$name = $_FILES["uploadFile"]["name"][$key];
move_uploaded_file($tmp_name, "$uploads_dir/$name");
$_FILES['userfile']['error']
?>
请注意我是一个完整的编程新手,所以非常感谢一个非常简单的解释!
提前致谢
答案 0 :(得分:0)
这是@aditya
PHP Core
Directive Local Value Master Value
allow_call_time_pass_reference On On
allow_url_fopen On On
allow_url_include Off Off
always_populate_raw_post_data Off Off
arg_separator.input & &
arg_separator.output & &
asp_tags Off Off
auto_append_file /usr/lib/php/foot.php /usr/lib/php/foot.php
auto_globals_jit On On
auto_prepend_file /usr/lib/php/head.php /usr/lib/php/head.php
browscap no value no value
default_charset no value no value
default_mimetype text/html text/html
define_syslog_variables Off Off
disable_classes no value no value
disable_functions system, show_source, exec, shell_exec, proc_open, passthru, set_time_limit, ini_restore, mysql_list_dbs, ini_alter, dl, pfsockopen, openlog, syslog, symlink, link, chgrp, leak, popen, escapeshellcmd, apache_child_terminate, apache_get_modules, apache_get_version, apache_getenv, apache_note, apache_setenv, virtual, mb_send_mail system, show_source, exec, shell_exec, proc_open, passthru, set_time_limit, ini_restore, mysql_list_dbs, ini_alter, dl, pfsockopen, openlog, syslog, symlink, link, chgrp, leak, popen, escapeshellcmd, apache_child_terminate, apache_get_modules, apache_get_version, apache_getenv, apache_note, apache_setenv, virtual, mb_send_mail
display_errors On On
display_startup_errors Off Off
doc_root no value no value
docref_ext no value no value
docref_root no value no value
enable_dl Off Off
error_append_string <br><table border='1' cellpadding='2' bgcolor='#FFFFDF' bordercolor='#E8B900' align='center'><tr><td><div align='center'><a href='http://www.000webhost.com/'><font face='Arial' size='1' color='#000000'>Free Web Hosting</font></a></div></td></tr></table> <br><table border='1' cellpadding='2' bgcolor='#FFFFDF' bordercolor='#E8B900' align='center'><tr><td><div align='center'><a href='http://www.000webhost.com/'><font face='Arial' size='1' color='#000000'>Free Web Hosting</font></a></div></td></tr></table>
error_log error_log error_log
error_prepend_string <br><table border='1' cellpadding='2' bgcolor='#FFFFDF' bordercolor='#E8B900' align='center'><tr><td><font face='Arial' size='1' color='#000000'><b>PHP Error Message</b></font></td></tr></table> <br><table border='1' cellpadding='2' bgcolor='#FFFFDF' bordercolor='#E8B900' align='center'><tr><td><font face='Arial' size='1' color='#000000'><b>PHP Error Message</b></font></td></tr></table>
error_reporting 6135 6135
expose_php On On
extension_dir /usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613 /usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613
file_uploads On On
highlight.bg #FFFFFF #FFFFFF
highlight.comment #FF8000 #FF8000
highlight.default #0000BB #0000BB
highlight.html #000000 #000000
highlight.keyword #007700 #007700
highlight.string #DD0000 #DD0000
html_errors On On
ignore_repeated_errors On On
ignore_repeated_source On On
ignore_user_abort Off Off
implicit_flush Off Off
include_path .:/usr/lib/php:/usr/local/lib/php .:/usr/lib/php:/usr/local/lib/php
log_errors Off Off
log_errors_max_len 1024 1024
magic_quotes_gpc On On
magic_quotes_runtime Off Off
magic_quotes_sybase Off Off
mail.force_extra_parameters no value no value
max_execution_time 10 10
max_file_uploads 20 20
max_input_nesting_level 64 64
max_input_time 10 10
memory_limit 64M 64M
open_basedir /home/:/usr/lib/php:/tmp no value
output_buffering 1 1
output_handler no value no value
post_max_size 2M 2M
precision 12 12
realpath_cache_size 16K 16K
realpath_cache_ttl 120 120
register_argc_argv Off Off
register_globals Off Off
register_long_arrays On On
report_memleaks On On
report_zend_debug On On
safe_mode Off Off
safe_mode_exec_dir no value no value
safe_mode_gid Off Off
safe_mode_include_dir no value no value
sendmail_from no value no value
sendmail_path /usr/local/bin/phpsendmail /usr/local/bin/phpsendmail
serialize_precision 100 100
short_open_tag On On
SMTP localhost localhost
smtp_port 25 25
sql.safe_mode Off Off
track_errors Off Off
unserialize_callback_func no value no value
upload_max_filesize 2M 2M
upload_tmp_dir /tmp /tmp
user_dir no value no value
variables_order EGPCS EGPCS
xmlrpc_error_number 0 0
xmlrpc_errors Off Off
y2k_compliance On On
zend.ze1_compatibility_mode Off
答案 1 :(得分:-1)
//什么是$ key。我没有看到需要。尝试下面的代码。和白色的屏幕?总是为您的测试代码打印一些消息。 $ uploads_dir ='uploads';
$tmp_name = $_FILES["uploadFile"]["tmp_name"];
$name = $_FILES["uploadFile"]["name"];
$moved = move_uploaded_file($tmp_name, "$uploads_dir/$name");
if($moved && file_exists("$uploads_dir/$name")){
echo 'file uploaded successfully';
}
else{
echo $_FILES['userfile']['error'].' -- ailed to move file';
}
对于你要面对的第二个问题, 你需要在php.ini中设置upload_max_filesize和post_max_size的值:
上传文件的最大允许大小。 upload_max_filesize = 40M
必须大于或等于upload_max_filesize post_max_size = 40M