We help IT Professionals succeed at work.
Get Started

Why doesn't this upload script work?

Bruce Gust
Bruce Gust asked
Last Modified: 2015-03-09
Here's my code:

		$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;
		$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;
				$uploadOk = 0;
		$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))  
			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?
Watch Question
Most Valuable Expert 2011
Author of the Year 2014
This problem has been solved!
Unlock 2 Answers and 3 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE