Jump to content

Banging head on desk -- need a second brain please.


pornophobic

Recommended Posts

I've been trying to wrap my head around this for about two hours now. The file uploads just fine, the entry goes into the database just fine, EXCEPT for the file name like it's supposed to do. I wrote the code from scratch... it worked fine, then it broke (that's the way it's supposed to work, right?)

Anyways, if anyone could take a look-see and point out what I'm missing? I've tried throwing errors on all the queries, I've made sure the filename is passed from the upload form, the form does have the proper enctype.

 

require 'dbconfig.php';$title = escape($_POST['title']);$content= escape($_POST['content']);$time = time();//Check the file.if (!empty($_FILES['attachment'])) {//$filename = the name as saved on user's the computer.//$filename = $_FILES['attachment']['name'];if($_FILES['attachment']['type'] === 'image/jpeg' || $_FILES['attachment']['type'] === 'image/jpg' || $_FILES['attachment']['type'] === 'application/pdf') {	//Move the file only if it's uploaded.		if (is_uploaded_file($_FILES['attachment']['tmp_name'])) {			//Whoops, an error.			if (!move_uploaded_file($_FILES['attachment']['tmp_name'], './attachments/' . $_FILES['attachment']['name'])) { die('Error: File not uploaded. Please make sure it is a JPEG image or a PDF document.'); }			else {				$filename = $_FILES['attachment']['name'];			}	}}}if( $filename = '' || empty($_FILES['attachment'] )) {die('No attachment found. Please <a href="javascript: history.go(-1)">Go back</a>');}if ($title === '') {die('News title is empty. Please <a href="javascript: history.go(-1)">Go back</a>');}if ($content === '') {die('News content is empty. Please <a href="javascript: history.go(-1)">Go back</a>');}else {if (mysql_query("INSERT INTO news (news_title, news_content, news_posted, news_edited, news_attach_path) VALUES ('$title', '$content', '$time', '0', '$filename')") or die(mysql_error())) {	$posted = true;}else {	$posted = false;}}?>

 

Strange how that happens, I decide to post for a second opinion and I solve it right after.

 

I changed:

 

if( $filename = '' || empty($_FILES['attachment'] )) {

 

 

to

 

 

if( $filename === '' || empty($_FILES['attachment'] )) {

 

 

and it works just fine now.

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.