Hi all...
The protblrm I am currently having involves $_FILES. I am using thr multipart/form-data enctype but the files array is not always populated. The array gets populated for some files, but not otherd. Does this mean I need to use the ob_start() function as it is a self submitting form
thznkx
PHP Files Array
-
- Posts: 66
- Joined: Thu Jan 12, 2012 3:54 pm
- Contact:
PHP Files Array
Last edited by jacek on Tue Jan 24, 2012 5:57 pm, edited 1 time in total.
Reason: Fixed title.
Reason: Fixed title.
Re: PHP Files Arrau
It has nothing to do with ob_start at all(). You are probably making a mess of the html somehow so that it doesn't work in some way.
Post your code and we will take a look
Post your code and we will take a look
-
- Posts: 66
- Joined: Thu Jan 12, 2012 3:54 pm
- Contact:
Re: PHP Files Array
OK, my html code is
<form action="index.php" method="POST" enctype="multipart/form-data"> <input type="file" name="upload"><input type="submit" name="submit"> </form>My PHP code is
<?php if(isset($_POST["submit"])) { print_r($_FILES); } ?>Like I said, sometimes the array is populated and sometimes not I am mainly using this code on a music sharing site where, I guess, files could be quite large
Re: PHP Files Array
Is that the entire code ? I don't really see any problems that would break it. method="POST" should be lower-case but I doubt that will be the cause.
-
- Posts: 66
- Joined: Thu Jan 12, 2012 3:54 pm
- Contact:
Re: PHP Files Array
Well I did have an allowed extensions array to filter unwanted extensions
Notice: Undefined index: upload in C:\Webroot\htdocs\ypload\index.php on line 10
when the $_FILES array isn't populated
$allowed = array("mp3","wma","ogg");but thats the only other thing. I also had
if(isset($_POST['submit'])) { print_r($_FILES); }and now, when I take out the if(isset($_POST['submit'])); line, I get
Notice: Undefined index: upload in C:\Webroot\htdocs\ypload\index.php on line 10
when the $_FILES array isn't populated
Re: PHP Files Array
Could you just post the full script ? I can't really think what it looks likewrichards8 wrote:but thats the only other thing. I also had
That would be because you try to use it before you check to make sure it's there.wrichards8 wrote:and now, when I take out the if(isset($_POST['submit'])); line, I get
Notice: Undefined index: upload in C:\Webroot\htdocs\ypload\index.php on line 10
when the $_FILES array isn't populated
Essentially you want
if (isset($_FILES['upload']['name'])){ // Do file things here. }
-
- Posts: 66
- Joined: Thu Jan 12, 2012 3:54 pm
- Contact:
Re: PHP Files Array
Sorry, heres the code in full
<form action="index.php" method="post" enctype="multipart/form-data"> <input type="file" name="upload"> <input type="submit" name="submit"> </form> <?php if(isset($_POST["submit"])) { print_r($_FILES); $allowed_exts = array("mp3","wma", "ogg"); $filename = strtolower($_FILES["upload"]["name"]); $filextend = substr($filename, -3); $filesize = $_FILES["upload"]["size"]; if(!in_array($filextend, $allowed_exts)) { echo "I can't upload ", $filextend, " files!"; } if($filesize > 10240000) { echo "This file can't be larger than 15MB"; } move_uploaded_file($_FILES["upload"]["tmp_name"], "uploads/". $_FILES["upload"]["name"]); } ?> ?>
Re: PHP Files Array
Well that looks okay, it could be that some files are above the servers upload size limit I guess ?