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;}}?>

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.