i'm having a bizarre issue with a form that seems to not want to post the file data array...

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="category" value="music" />
<input type="file" name="image_upload" class="multi" accept="jpg|jpeg" maxlength="1" />
<input type="submit" name="cat_music_img" value="Update" />
</form>

the following is a snippet i just inserted to return a set piece of file data (under normal circumstances it would pass to a script that would resize, create a thumbnail and populate data into mysql db):

if(isset($_POST['cat_music_img'])) {
	$category = $_POST['category'];
	$file = $_FILES['image_upload']['name'];
	echo $category . ' ' . $file;
}

it returns blank and with no errors at all. it's like it basically isn't picking up that a file's been uploaded at all. i am using a jquery script to allow for multi file uploading but turning this off doesn't make any difference.

using php v 5.2.6

any help appreciated!

sorry forgot to say that i have tried returning some of the other information from the (i.e. tmp_name etc) but it's not showing that either.

also just to clarify i use an almost identical script (the only difference is in what it does with the image) in another area and it works fine.

Recommended Answers

All 3 Replies

If your request carries text-data along with a file (text/binary) then a form html tag must have enctype attribute with multipart/form-data.

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data" >
<input type="hidden" name="category" value="music" />
<input type="file" name="image_upload" class="multi" accept="jpg|jpeg" maxlength="1" />
<input type="submit" name="cat_music_img" value="Update" />
</form>

Hahahah! Now I feel like a complete dunce, sorry for wasting your time, I can't believe I forgot to put that in...

Thanks though!

and for multiple files save? how to use array to get information?
$file = $_FILES;
for file upload 2?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.