I am struggling with creating an audio file upload form for my website. I feel like the upload section works properly, but when I try it out and I submit the uploading it goes to the right php page, but the screen is all white with nothing on it.
My goal is to move the uploaded audio file into the uploads directory on my server.
I have the following code:
<!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>
and for the php page:
<?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']
?>
Please note that I am a complete newbie with programming, so a really simple explanation would be much appreciated!
Thanks in advance
This is for @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
//whats with $key. I dont see the need for that. try the code below. And the white screen? always print some message for your test code. $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';
}
For the second issue you are facing, You need to set the value of upload_max_filesize and post_max_size in your php.ini :
; Maximum allowed size for uploaded files. upload_max_filesize = 40M
; Must be greater than or equal to upload_max_filesize post_max_size = 40M
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.