Avatar of Bruce Gust
Bruce Gust
Flag for United States of America asked on

Why doesn't this upload script work?

Here's my code:

		if(isset($_FILES['doc_1'])&&!empty($_FILES['doc_1']['name']))
		{
		$pathinfo = pathinfo($_FILES['doc_1']['name']);
		//$new_name = $pathinfo['filename'].'_'.$novie_id.'.'.$pathinfo['extension'];
		$target = "../docs/"; 
		$target = $target . basename( $_FILES['doc_1']['name']);
		echo $target;
		$uploadOk=1; 
		$extension = $pathinfo['extension'];
			if($extension=="jpg" OR $extension=="jpeg" OR $extension=="JPG" OR $extension=="GIF" OR  $extension=="gif" OR $extension=="PNG" OR $extension=="png" OR $extension=="doc" or 
			$extension=="docx" or $extension=="pdf" OR $extension=="xls" OR $extension=="xlsx" OR $extension=="ppt" OR $extension=="pptx" OR $extension=="txt" OR $extension=="pub" OR $extension=="wps"
			or $extension=="bmp" OR $extension=="BMP")
			{
				$uploadOk = 1;
			} 
			else 
			{
				$uploadOk = 0;
				//header("Location:doc_badfile.php");
				//exit();
			}
			
		$upload_dir = "../docs/";
		if (file_exists($upload_dir) && is_writable($upload_dir)) {
		echo "you're good to go";
		}
		else {
			echo 'Upload directory is not writable, or does not exist.';
		}
			
			if(!move_uploaded_file($_FILES['doc_1']['name'], $target))  
			{
			header("Location:doc_noupload.php");
			exit();
			}
			echo "OK";
			
		}
	
	}

Open in new window


When I comment out the "header("Location:doc_no_upload.php)" dynamic so I can see the target and read all of the other indicators I've been fooling with, there shouldn't be anything keeping this file from uploading.

I've been looking at this for an hour and half. I've got other scripts that follow the same format - no problem. But this one hates me for some reason and I can't figure out what's wrong.

File permissions on target directory are set to 777 so that's good.

Where am I blowing it?
PHP

Avatar of undefined
Last Comment
Bruce Gust

8/22/2022 - Mon
SOLUTION
Dave Baldwin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Bruce Gust

ASKER
Gentlemen, I did get it to work by simply changing the name of the file field. Before I had:

<input name="dir_1" type="file" size="61">

I changed that to:

<input name="attachment_1" type="file" size="61">

When I did that, the skies cleared, the sun came up and the birds began to sing.

Perhaps, "dir" being referenced as a reserved word, was a dealbreaker. At this point, that's what I'm leaning towards as far as an explanation, but I got it done and I appreciate your help.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy