PHP/Apache Permission Problem?

I'm using the script below, database settings were definately set correctly, their removed now for security. Are there any modifications I need to make to user permissions for this script to work correctly. Keep in mind it must be able to move a file using "rename". This is running on Fedora 6 with apache. This was working fine on another apache server (godaddy).


// Variables
$dbServer = "";
$dbuser = "";
$dbpass = "";
$dbDatabase = "imgsrv";
$dbTable = "imagetable";
$dbAliasImgName = "imageName";      //name of field for image name in your database
$dbAliasImgSize = "imageSize";      //name of field for image size
$dbAliasMD5 = "MD5";
$dbAliasAnswer = "Answer";
$dbAliasAgent = "Agent";
$dbAliasIP = "IP";
$currentDir = getcwd();
$uploadDir = "/Images";


 <!-- The data encoding type, enctype, MUST be specified as below -->

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="0">

<form action="randomimage.php" name=addanswer method="POST">

<link href="css/Style1.css" rel="stylesheet" type="text/css" />
<BODY onload="document.addanswer.Answer.focus();" >

    <table border = 1>
    <td>Add Answer</td><tr align =top>


/* Customise this line to change to your images folder */
$dir = 'Images/unanswered/';
$dh = opendir($dir);
/* The following loop scans the directory specified ignoring folders and Thumbs.db */
while (false !== ($filename = readdir($dh))) {
if($filename == "Thumbs.db" || is_dir($filename)){
$files[] = $filename;

/* Generate a random number */
$nooffildi = count($files);
$nooffiles = ($nooffildi-1);
$randnum = rand(0,$nooffiles);

/* print the result */
echo "<IMG SRC='$dir/$files[$randnum]' ALT='$files[$randnum]' BORDER='0'><br>";

echo "<input type=hidden name=\"FileName\" value=\"$dir/$files[$randnum]\">";

Answer: <input name="Answer" type="text" value="" /><br>
<input type="submit" value="Add Answer" />



 if (sizeof($_POST) > 0){  


$size = filesize($filename);

$imagename = basename($filename);

$movetopath = "Images/";
$newfilename = $movetopath.$imagename;
rename($filename, $newfilename); //rename is used for moving as well

          //     SQL Connect
          $myConn = mysql_connect($dbServer, $dbuser, $dbpass)
                    or die("Failed Connection to $dbServer; No connection to Database; ".mysql_error());
          //     SQL Adjusts & Variabless
          mysql_select_db($dbDatabase, $myConn);      //$dbDatabase in place of first column
          $mySql = "";


                   $MD5 = preg_replace("[.jpg]", "", $imagename);

                    //     SQL
                    $mySql = "SELECT COUNT($dbAliasImgName) AS result FROM $dbTable WHERE $dbAliasImgName = '" . $imagename. "'";
                    $result = mysql_query($mySql, $myConn) or die(mysql_error());
                    $mySql = "Insert into $dbTable ($dbAliasImgName, $dbAliasImgSize, $dbAliasMD5, $dbAliasAnswer, $dbAliasAgent,$dbAliasIP) values ('$imagename', '$size', '$MD5', '$Answer', '$Agent', '$ipaddr')";
                    mysql_query($mySql, $myConn) or die(mysql_error());

echo "Your answer has been added."
<?php     }

Who is Participating?
ch2Connect With a Mentor Commented:

Can you tell us which php error occurs? and also the phpversion.

JPERKS1985Author Commented:
No php error occurs, the file doesn't move and there is no database entry added.
Muhammad WasifCommented:
confirm what values you have in $filename and $newfilename variables. use echo print these values and let us know.
JPERKS1985Author Commented:
When I echoed them they are the correct values.
All Courses

From novice to tech pro — start learning today.