PHP不进入foreach循环(php not getting inside foreach loop)

系统教程 行业动态 更新时间:2024-06-14 16:58:30
PHP不进入foreach循环(php not getting inside foreach loop)

我发誓这个剧本昨晚效果不错,但今天无法使用它。 它并没有进入foreach循环,但我不知道为什么。 即使我选择一个文件并单击提交,$ _FILES数组也是null。

基本上这个脚本有一个文件输入标签,并使用jQuery,如果用户选择一个文件,它会添加另一个文件输入标签。 当点击提交按钮时,调用PHP。

<?php //used for firePHP include('PHP/FirePHPCore/fb.php'); ob_start(); $success = false; $error = ""; $allowable_types = array( 'image/jpeg', 'image/pjpeg', 'image/jpg', 'image/jpe', 'image/gif', 'image/png' ); ################################################################# //NOT GETTING INSIDE THE FOREACH LOOP. $_FILES array is always null ################################################################## //loops through the files that the user has chosen to be uploaded them and moves them to the Images/uploaded folder foreach($_FILES as $key => $value) { if(!empty($_FILES[$key])) { if($_FILES[$key]['error'] == 0) { if(in_array($_FILES[$key]['type'], $allowable_types) && ($_FILES[$key]['size'] < 5000000)) { if(!file_exists("Images/uploaded/".$_FILES[$key]['name'])) { move_uploaded_file($_FILES[$key]['tmp_name'], "Images/uploaded/".$_FILES[$key]['name']); $success = true; } else { $error = "<h3 class=\"bad\">At least one of the files already exists</h3>"; } } else { $error = "<h3 class=\"bad\">At least one of the files you've selected is either too large or not the correct file type</h3>"; } } elseif($_FILES[$key]['error'] == 4) { } else { $error = "<h3 class=\"bad\">An error occurred while trying to upload one of the files</h3>"; } } else { $error = "<h3 class=\"bad\">You need to select a file</h3>"; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="refresh" content="1205"> <link rel="stylesheet" type="text/css" href="CSS/reset.css" /> <link rel="stylesheet" type="text/css" href="CSS/uploadFile.css" /> <link rel="stylesheet" type="text/css" href="CSS/galleria.css" /> <script type="text/ecmascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript" src="JS/galleria.jquery.js"></script> <script type="text/javascript"> $(document).ready(function() { var i = 1; //gives the first li the class .active so that it shows the large version as if it's been clicked. //-- used for the gallery page $('#content ul.gallery li:first-child').addClass('active'); //fades the links on hover -- used for the nav links $('#header ul li a').hover(function() { $(this).fadeTo(300, 0.3); },function() { $(this).fadeTo(300, 1); }); $('input:file:last').live('change',function() { var file = $(this).val(); if(file !== null && file !== "") { if(i < 6) { $(this).after("<input type=\"file\" name=\"uploadedFile"+i+"\" value=\"\" />"); i++; } } }); }); </script> <meta name="keywords" content="Steph Mcclisch Photography Portfolio Pictures" /> <title>Steph McClish Photography</title> </head> <body> <div id="floater"></div> <div id="wrapper"> <div id="content"> <?php if($success) { echo "<h3 class=\"good\">Files Uploaded Successfully!</h3>"; } elseif ($error) { echo $error; } ?> <h4>Choose the files to be uploaded</h4> <form action="<?php $_SERVER['PHP_SELF']?>" method="post" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="500000" /> <input type="file" name="uploadedFile0" value="" /> <button type="submit" name="login">Submit</button> </form> <h5><a href="PHP/Manage.php">Manage Files/Folders</a></h5> </div> </div> </body> </html>

I swear this script worked fine last night but can't get it to work today. It's not getting inside of the foreach loop though and i don't know why. the $_FILES array is null even if i select a file and click submit.

Basically this script has a file input tag and using jquery, if a user selects a file, it adds another file input tag. When the submit button is clicked, the PHP is called.

<?php //used for firePHP include('PHP/FirePHPCore/fb.php'); ob_start(); $success = false; $error = ""; $allowable_types = array( 'image/jpeg', 'image/pjpeg', 'image/jpg', 'image/jpe', 'image/gif', 'image/png' ); ################################################################# //NOT GETTING INSIDE THE FOREACH LOOP. $_FILES array is always null ################################################################## //loops through the files that the user has chosen to be uploaded them and moves them to the Images/uploaded folder foreach($_FILES as $key => $value) { if(!empty($_FILES[$key])) { if($_FILES[$key]['error'] == 0) { if(in_array($_FILES[$key]['type'], $allowable_types) && ($_FILES[$key]['size'] < 5000000)) { if(!file_exists("Images/uploaded/".$_FILES[$key]['name'])) { move_uploaded_file($_FILES[$key]['tmp_name'], "Images/uploaded/".$_FILES[$key]['name']); $success = true; } else { $error = "<h3 class=\"bad\">At least one of the files already exists</h3>"; } } else { $error = "<h3 class=\"bad\">At least one of the files you've selected is either too large or not the correct file type</h3>"; } } elseif($_FILES[$key]['error'] == 4) { } else { $error = "<h3 class=\"bad\">An error occurred while trying to upload one of the files</h3>"; } } else { $error = "<h3 class=\"bad\">You need to select a file</h3>"; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="refresh" content="1205"> <link rel="stylesheet" type="text/css" href="CSS/reset.css" /> <link rel="stylesheet" type="text/css" href="CSS/uploadFile.css" /> <link rel="stylesheet" type="text/css" href="CSS/galleria.css" /> <script type="text/ecmascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript" src="JS/galleria.jquery.js"></script> <script type="text/javascript"> $(document).ready(function() { var i = 1; //gives the first li the class .active so that it shows the large version as if it's been clicked. //-- used for the gallery page $('#content ul.gallery li:first-child').addClass('active'); //fades the links on hover -- used for the nav links $('#header ul li a').hover(function() { $(this).fadeTo(300, 0.3); },function() { $(this).fadeTo(300, 1); }); $('input:file:last').live('change',function() { var file = $(this).val(); if(file !== null && file !== "") { if(i < 6) { $(this).after("<input type=\"file\" name=\"uploadedFile"+i+"\" value=\"\" />"); i++; } } }); }); </script> <meta name="keywords" content="Steph Mcclisch Photography Portfolio Pictures" /> <title>Steph McClish Photography</title> </head> <body> <div id="floater"></div> <div id="wrapper"> <div id="content"> <?php if($success) { echo "<h3 class=\"good\">Files Uploaded Successfully!</h3>"; } elseif ($error) { echo $error; } ?> <h4>Choose the files to be uploaded</h4> <form action="<?php $_SERVER['PHP_SELF']?>" method="post" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="500000" /> <input type="file" name="uploadedFile0" value="" /> <button type="submit" name="login">Submit</button> </form> <h5><a href="PHP/Manage.php">Manage Files/Folders</a></h5> </div> </div> </body> </html>

最满意答案

这一切都必须与我的Wamp服务器设置。 在菜单栏中的wamp图标上,我进入了php> php设置>文件上传。 只需点击一次,就可以修复所有问题。

It all had to do with my Wamp server setup. On the wamp icon in the menu bar i went php>php settings>file uploads. Just clicked that once and it fixed everything.

更多推荐

本文发布于:2023-04-15 03:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/ed02efd66dd1eb2a2d3f366a46027df0.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:foreach   PHP   loop   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!