从不同的PC检索图像

时间:2014-02-24 16:09:27

标签: php html

我正在开发一个网站(HTML,CSS,PHP,JavaScript),需要访问不同的PC并获取图像。然后我想向任何用户使用我的程序显示这些图像。

例如,我想从我的电脑上打开pcA上的文件夹A并获取所有图像 该文件夹并将其显示在我的网站中。这可能吗?

这是我的代码:

$dir1 = "pictures/";
$dir2 = "pictures2/";
$dir3 = "pictures3/";

 $basedir = array(
    'basedir1' => $dir1 ,
    'basedir2' => $dir2 ,
    'basedir3' => $dir3 
   );

    function readGPSinfoEXIF($image_full_name)
    {
    if (file_exists($image_full_name) )
     {
       $exif=exif_read_data($image_full_name, 0, true);
       if ( !empty($exif['GPS']['GPSLatitude']) )
       {

         if(!$exif || $exif['GPS']['GPSLatitude'] == '') 
          {
           return false; 
          } 

          else 
           {
            $lat_ref = $exif['GPS']['GPSLatitudeRef']; 
            $lat = $exif['GPS']['GPSLatitude'];
            list($num, $dec) = explode('/', $lat[0]);
            $lat_s = $num / $dec;
            list($num, $dec) = explode('/', $lat[1]);
            $lat_m = $num / $dec;
            list($num, $dec) = explode('/', $lat[2]);
            $lat_v = $num / $dec;

            $lon_ref = $exif['GPS']['GPSLongitudeRef'];
            $lon = $exif['GPS']['GPSLongitude'];
            list($num, $dec) = explode('/', $lon[0]);
            $lon_s = $num / $dec;
            list($num, $dec) = explode('/', $lon[1]);
            $lon_m = $num / $dec;
            list($num, $dec) = explode('/', $lon[2]);
            $lon_v = $num / $dec;

            $gps_int = array($lat_s + $lat_m / 60.0 + $lat_v / 3600.0, $lon_s + $lon_m / 60.0 + $lon_v / 3600.0);

            return $gps_int;
           }//end of else
        }//end of if checking if GPS value is not empty
      }//check if file exists
    }//end of function

             function dirImages($dir) 
                {
                 $d = dir($dir);
                 while (false!== ($file = $d->read())) 
                    {
                     $extension = substr($file, strrpos($file, '.')); 
                     if($extension == ".jpg" || $extension == ".jpeg" || $extension == ".gif" |$extension == ".png") 
                     $images[$file] = $file; 
                    }
                    $d->close();         
                    return $images; 
                }

$COUNTER_IMAGE = 0;   

foreach ($basedir as $dir) // array of dirs path p.x pictures/
   {
        $array = dirImages($dir);
        $counter =count($array);

        $sql_ip = "SELECT dir FROM users WHERE dir = '".$dir."' ";
        $result_ip = mysql_query($sql_ip);
        $row_ip = mysql_fetch_assoc($result_ip);

        if(empty($row_ip['dir']) )
           {              
             //inserting user details
             $insert_user_details= @mysql_query("
                INSERT INTO users 
                VALUES(
                '', 
                '$localIP', 
                '', 
                '".$dir."',
                '".$data['latitude']."', 
                '".$data['longitude']."',
                '".$data['ipAddress']."',
                '".$data['countryName']."',
                '".$data['cityName']."'
                ) ");
            }

            $sql_user = "SELECT user_id FROM users 
            WHERE  dir ='".$dir."'  ";
            $result_user = mysql_query($sql_user);
            $row_user = mysql_fetch_assoc($result_user);

            foreach ($array as $key) 
            {
                $image_full_name = $dir."/".$key; 
                $results = readGPSinfoEXIF($image_full_name);
                $latitude = $results[0];
                $longitude = $results[1];

                $sql = "SELECT * FROM monument_info 
                WHERE monument_longitude='".$longitude."' AND monument_latitude ='".$latitude."'  ";
                $result = mysql_query($sql);
                $row = mysql_fetch_assoc($result);

                                    if( ($longitude != $row['monument_longitude'])
                                    && ($latitude   != $row['monument_latitude']) 
                                    && empty($row['monument_longitude'])
                                    && empty($row['monument_latitude']) 
                                    )

                                    {
                                        //$COUNTER_IMAGE = $COUNTER_IMAGE + 1;
                                        $insert_monument_details= @mysql_query("
                                        INSERT INTO monument_info 
                                        VALUES(
                                        '".$row_user['user_id']."', 
                                        '$longitude', 
                                        '$latitude',
                                        '', 
                                        '',
                                        '".$image_full_name."'
                                        ) ");

                                        if (file_exists($image_full_name) )//This if statement hides a bug
                                            {
                                              echo "<img  src='".$image_full_name."'   widht=350 height='300' />&nbsp;&nbsp;&nbsp;";
                                            }
                                    }

                                else
                                {
                                    if (file_exists($image_full_name) )//This if statement hides a bug
                                    {
                                        if( !empty($row['monument_longitude']) && !empty($row['monument_latitude']) )
                                        {
                                          echo "<img  src='".$image_full_name."'   widht=350 height='300' />&nbsp;&nbsp;&nbsp;";
                                        }
                                    }
                                }
            }//end of foreach of printing images in folder
    }

0 个答案:

没有答案