2012-02-15 73 views
0

讓我快速解釋我的問題。
我正在寫一個JavaScript函數來避免我的響應式WordPress主題中的額外帶寬。所以基本上我會根據用戶的屏幕分辨率將src切換爲一系列圖像。 我需要的是每個案例的「確定」名稱。更改保存的圖片名稱

像這樣:

if if (wWidth > 769) ---> imagename-desktop.jpg 
else if (wWidth <= 768 && wWidth>= 481) ---> imagename-ipad.jpg 
else if (wWidth <= 480) ---> imagename-iphone.jpg 

其實我現在是一樣的東西

imagename-768x300.jpg 
imagename-480x200.jpg 
imagename-1300x500.jpg 

回答

0

看到這個例子。

<?php 
$path = "D:/x"; 
$dh = opendir($path); 

while (($file = readdir($dh)) !== false) { 
    if($file != "." && $file != "..") { 
     $imageNameAR = explode("-",$file); 
     $imageName = $imageNameAR[0]; 
     $imageLast = $imageNameAR[1]; 
     switch($imageLast) 
     { 
      case "768x300.jpg": 
      { 
       $newName = $imageName . "-iphone.jpg"; 
       rename($path."/".$file, $path."/".$newName); 
       break; 
      }   
      case "480x200.jpg": 
      { 
       $newName = $imageName . "-ipad.jpg"; 
       rename($path."/".$file, $path."/".$newName); 
       break; 
      } 
      case "1300x500.jpg": 
      { 
       $newName = $imageName . "-desktop.jpg"; 
       rename($path."/".$file, $path."/".$newName); 
       break; 
      } 
     } 
    } 
} 
closedir($dh); 
?>