Solved

PHP/Apache Permission Problem?

Posted on 2006-11-18
4
316 Views
Last Modified: 2006-11-21
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).


<html>
<body>
<?php


//
// 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";
$ipaddr = $HTTP_SERVER_VARS["REMOTE_ADDR"];


?>

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

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



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


</HEAD>
<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>
   <td>


<?php


/* 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)){
}else{
$files[] = $filename;
}
}
closedir($dh);

/* Generate a random number */
$nooffildi = count($files);
$nooffiles = ($nooffildi-1);
srand((double)microtime()*1000000);
$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" />





</td>
          </form>

   <?      




 if (sizeof($_POST) > 0){  


$filename=$_POST['FileName'];
$answer=$_POST['Answer'];

$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());
                   
             

         
          mysql_close($myConn);
echo "Your answer has been added."
     ?>
         
<?php     }

?>
</body>
</html>
0
Comment
Question by:JPERKS1985
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
ch2 earned 500 total points
ID: 17973118
Hi

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

ch2
0
 
LVL 1

Author Comment

by:JPERKS1985
ID: 17973720
No php error occurs, the file doesn't move and there is no database entry added.
0
 
LVL 20

Expert Comment

by:Muhammad Wasif
ID: 17973909
confirm what values you have in $filename and $newfilename variables. use echo print these values and let us know.
0
 
LVL 1

Author Comment

by:JPERKS1985
ID: 17985554
When I echoed them they are the correct values.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question