mmilano - first thanks for your help. I'm also posting my finished code in case anyone wants it.
My script is now working. I think my problem was with the upload_tmp_dir setting. I had set this to the same directory as the "/proofs/" directory that I was trying to upload to. This directory was in the same directory as my actual PHP script. I'm not sure why it should matter either way, but I created a new php_tmp directory within WebServer/Documents, and set the upload_tmp_dir in my php.ini file to that. Problem solved.
Your suggestions did solve my PERMISSION DENIED errors. Thanks!
<?php
/* This script contains two functions -
1) updateURL() - updates a mysql database with supplied data
2) moveFileTo() - moves an uploaded file to specified location
*/
function updateURL($newFilename,$newProjectID) {
/* This function updates the mysql proofs database with a
new URL and a project ID number, supplied from $_POST variables.
Function is now working - ultimately need to add error handling
and a mechanism for generating the revision number field and a
revision date and time fields */
echo "function updateURL() called<br><br>";
echo 'function argument $newFilename is: '."$newFilename<br><br>";
echo 'function argument $newProjectID is: '."$newProjectID<br><br>";
echo "--------------------------------------------------------<br><br>";
/* establish database connection */
$connection = mysql_pconnect("127.0.0.1", "root","");
/* use database pe_project_manager */
$db_selected = mysql_select_db("pe_projectmanager");
if (!$db_selected) {
echo "Failed to connect to pe_projectmanager<br><br>";
}
/* get resultset of all proofs */
$allProofs = mysql_query("select * from proofs");
/* calculate value for the next primary key - this variable
currently not used as primary key is auto-incrementing */
$lastKey = mysql_num_rows($allProofs);
$nextKey = $lastKey + 1;
/* build insert query */
$insertQuery = 'insert into proofs set proof_URL="'."$newURL".'", project_id="'."$newProjectID".'"';
echo 'mysql_query string is: ' . "$insertQuery<br><br>";
echo "--------------------------------------------------------<br><br>";
/* execute insert query */
mysql_query($insertQuery);
} /* *** end function updateURL *** */
function moveFileTo($newFilename, $newPath) {
/* This function should move an uplaoded file to a new destination,
supplied by the arguments $newFilename and $newPath */
echo "function moveFileTo() called.<br><br>";
echo 'function argument $newFilename is: '."$newFilename<br><br>";
echo 'function argument $newPath is: '."$newPath<br><br>";
/* Check to see that the $_FILES array has been populated with something */
if(!isset($_FILES['theFile'])) {
echo "Error! The expected file wasn't a part of the submitted form<br><br>";
}
/* Check to see that the $_FILES 'error' value is good */
if($_FILES['theFile']['error'] != UPLOAD_ERR_OK) {
echo "Error! The file uploaded failed.<br>";
}
/* Concatenate path and filename */
$pathAndFile = "$newPath"."$newFilename";
echo "PathAndFile is $pathAndFile<br>";
/* move uploaded file to $pathAndFile */
move_uploaded_file($_FILES['theFile']['tmp_name'], "$pathAndFile");
} /* END file upload function */
/* get variables from $_POST and $_FILES */
$newProjectID = $_POST['project_id'];
$newFilename = $_FILES['theFile']['name'];
/* assign path for permanent file location */
$newPath = "/Library/WebServer/Documents/www/lizard/proofs/";
/* call function to update MySQL data */
updateURL($newFilename, $newProjectID);
/* call function to move file to permanent location */
moveFileTo($newFilename, $newPath);
?>