PHP File Upload Problem

I have a web server running Windows Server 2003 Enterprise with WAMP Server 2.0. One of the websites using the server requires file upload functionality. I achieved this with the attached code, and it worked fine on my localhost. Then I copied it to the server and it no longer works. When a file is uploaded, there is no error message from PHP, and I was able to return the element of $_FILE for the uploaded file, which looks like this:
Array ( [name] => DEC-2009-11-08-PM.mp3 [type] => audio/mp3 [tmp_name] => C:\WINDOWS\Temp\php32.tmp [error] => 0 [size] => 3753230 )

I have tried changing the tmp directory to several different folders, including one inside the PHP directory within wamp. None of these worked. I have granted full permissions to Users on the server, but still the file does not appear inside the Temp directory.

In the move_uploaded_file part of the script, the else block is used because move_uploaded file fails, but the error element in the array is still 0, meaning a successful upload, and the array still gives a path for the Temp file (which is not there).

Thanks in advance!
<?php
if ($_POST)
	{
		$thedate = explode("/", trim($_POST['date']));
		$thedate = $thedate[2] . "-" . $thedate[1] . "-" . $thedate[0];

		if(move_uploaded_file($_FILES['file']['tmp-name'], "../files/sermons/" . "DEC-" . $thedate . "-" . trim($_POST['service']) . ".mp3"))
		{
		    $csv = file_get_contents("../files/sermons/sermons.csv");
		    $csv .=
		    	"\r\n" . $thedate . "," . 
		    	str_replace(",", "[comma]", trim($_POST['service'])) . "," . 
		   		str_replace(",", "[comma]", trim($_POST['preacher'])) . "," . 
		        str_replace(",", "[comma]", trim($_POST['subject'])) . "," . 
		        str_replace(",", "[comma]", trim($_POST['reading'])) . "," .
		        "DEC-" . $thedate . "-" . trim($_POST['service']) . ".mp3";
		    file_put_contents("../files/sermons/sermons.csv", $csv);
		    echo "File upload was (probably) successful.";
		}
		else
		{
		    echo "There was an error uploading the file, please try again!";
		    print_r($_FILES['file']);
		    echo "../files/sermons/" . "DEC-" . $thedate . "-" . $_POST['service'] . ".mp3";
		    
		}
?> <!-- HTML for the page -->

Open in new window

LVL 2
EliotBallAsked:
Who is Participating?
 
hieloConnect With a Mentor Commented:
>>if(move_uploaded_file($_FILES['file']['tmp-name'],...

It should be UNDERSCORE: ['temp_name']
NOT hyphen: ['tmp-name']
0
 
EliotBallAuthor Commented:
Can't believe I missed that! You just picked up some easy points there!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.