Jump to content

[SOLVED] IF Statement not working... FILES variables and form-data involved


Malevolence

Recommended Posts

I have a form that lets one upload a file. If there is no file present, then the if statement only uploads the strings from the other fields. If however, the file is present, then the script will upload the text and parse the file into binary which is then uploaded to the database alongside the simple string data.

 

The HTML for the Form:

<form enctype="multipart/form-data" name="addSong" action="addSong.php" method="POST">
			<div style="float: right; font-size: 0.9em;" align="right">
				<strong>Tip</strong> | Use the tag buttons found at the bottom left of the toolbar to structure your song.
			</div>

		Song Title:
		<input type="text" class="regField" name="stitle" value="" tabindex="1" />
		<br /><br />
		<textarea cols="95" rows="20" name="slyrics" value="" tabindex="2"></textarea>
		<br />
		<div align="right" style="float: right;">
		<input type="checkbox" name="sdraft" value="true"> Save as draft? 
		<input name="submit" type="submit" value="Save" /> 
		</div>
		Upload: <input type="hidden" name="MAX_FILE_SIZE" value="20000000" /><input name="supload" type="file" />
</form>

 

The PHP IF Statement that fails: (the rest is irrelevant)

if(!empty($_FILES['supload']) && $_FILES['supload']['size'] > 0) // If the upload field is not empty, set up the file upload.
{
// ^^^ THE ABOVE BIT DOESNT WORK ^^^
...
...
}
else // Otherwise just upload the lyrics
{
...
...
}

 

If anyone can help, thanks in advance.

What do you mean by "fails"?

 

What is displayed if you do a

<?php
echo '<pre>' . print_r($_FILES,true) . '</pre>';
?>

right before the "if" statement. Does the array have in it what you think it should?

 

Ken

When I say fails, it doesn't seem to recognise a file has been uploaded, however I echoed $_FILES['supload']['tmp_name'] and found that nothing was there. I then uploaded a small jpg file, which successfully uploaded and the if statement did work.

 

The problem therein lies that either mp3 files aren't allowed by my home webserver (unlikely) or that the filesize cannot be handled by my webserver. I will look at httpd.conf and see what I can fix, if anyone can point me to the main things I should be looking for, that would be helpful. Also, would 6-10mb be an allowed upload size on a conventional web host? seeing as you can't change this factor if you're paying for a host rather than a home-hosted server.

I had to fix a couple of things, but the main things were PHP upload limits in the php.ini file(s) as well as the mysql config to allow such a big request. I know that normal file storage is reccomended but this way is better for what I am doing, and the site is very exclusive and protected so not just anyone will upload several server-speed-crunching files.

 

Solved! - I guess...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.