Hi,

Have never posted yet, but have learned from reading the postings
and replies from everyone.  I'm sort of new to php, but I have more 
programming experience which has made learning php easy.  I'm not 
advanced, but I think I'm more than just a beginner.

I have recently starting learning how to use php to work with 
directories.  I have finally figured out the permissions, which were
a big headache.  We had to give write permissions to all to get it 
to work.  Which has to do with the permissions that apache starts 
with. We are using .htaccess to protect the site.  We are making 
sure, only a few can get into the folder that has write access.

I was wanting some advice on a few questions about my script and 
hope maybe someone can give me some advice or point me in the right 
direction. Let me explain my script.  I take images that are named 
like this: 

1911-7399.jpg 

I take the first 4 chars to make a variable called $deathVol.  The 
last 4 chars make a variable called $certNo.  I then take these
values and find the record located in a mysql table.  I get a value 
from the record, $deathID, which is what I use to reanme the images.
I then do another process with sets an Image field value to yes. 
Then I finally rename the picture. Here is the code:

<?php
$current_dir = '/.../.../public_html/.../'; 
$dir = opendir($current_dir); 
echo 'Upload directory is <b>'.$current_dir.'</b><br />';
echo 'Directory Listing:<br /><br />';
while($file = readdir($dir))
{
   $fileName = $file;

   if(!is_dir($file) && $file !== ".htaccess"
      && $file !== "browseDir.php" && $file !== "error_log")
   {
      echo '<b >File Name = '.$file.'</b><br />';

      $deathVol = substr($fileName,0,4);
      $certNo = substr($fileName, 5, 4);

      $conn = db_connect() or die(error());
      if($conn)
      {
         $query = "SELECT DeathID, Image
                   FROM ????
                   WHERE DeathVolume='".$deathVol."'
                   AND DeathCertNumber='".$certNo."'";

         $check = mysql_query($query);
         if($check)
         {
           $row = mysql_fetch_array($check);
           $deathID = $row['DeathID'];
           $newfileName = "dr".$deathID.".jpg";

           $query2 = "UPDATE ???? set Image='yes'
                      WHERE DeathID='".$deathID."'";

           $updateImage = mysql_query($query2);

           if($updateImage)
           {
             echo "Set Image field for ".$newfileName.".<br />";

             if(!rename($file, $newfileName))
                echo 'Could not rename...'.$file.".";
             else                                               
               echo 'Renamed '.$file.' to '.$newfileName.".";

            echo '<br /><br />';                                
            echo '<b>Preview: '.$newfileName.'</b><br />';
            echo '<img src="'.$newfileName.'" align="left">';   
            echo '<br /><br /><br /><br />';
          }
          else
          {
            echo 'Could not update Image field.<br /><br />';
          }
        }
        else
        {
           echo 'No record found<br /><br />';
        }
     }
     else
     {
         echo 'No connection';
     }
   }

  }

  closedir($dir);  
?>

I have gotten everything to work in this script, which it seems to 
be a slow process.  Is there anything I can do to make this script 
process faster.  I believe it is the rename command which takes so 
long.  I will be taking out the preview of the image, we were just 
doing this to ensure images were not corrupt, and figured out our 
problem was in the transferring of the images through FTP, and 
having everything set to transfer as ascii.  

I have tried to use mysql_fetch_row(), but I can't seem to get it to 
work for me.  I am using the mysql_fetch_array(), but I really don't 
need an array, since I'm only getting one record.  Any advice on 
this would help me.  I use Windows and IIS for developing, but the 
actual site uses UNIX and Apache.  There are many things I have to 
test online using FTP, since loaded modules has a lot to do with 
what functions you can use.   

The other question I have, is I need to store these images on 
another server for storage after completing the renaming of the 
images.  Can I just do this in the rename command, since I have seen 
it moves files also.  I have seen infomation about using wrappers, 
and will this be neccessary?  I realize I'll need to have 
permissions at the other site, which I will, and probably open that 
directory also.  I'm just confused on the way I can handle this.  
I've never worked with two different servers like this.  

I know I use double quotes and single quotes, but I have had many 
troubles with periods, which is a main control character in php.

Thanks ahead of time for any advice.  I did so much research just to 
get the rename command to work, and don't think I'll find my answers 
searching again. 

Tanya Holliday











The PHP_mySQL group is dedicated to learn more about the PHP_mySQL web database 
possibilities through group learning.  
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php_mysql/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to