2013-03-22 66 views
-5

我有兩個不同的文件,比如pdfjpeg擴展文件。我需要比較這兩個文件。如果是pdf我需要發送這個到附件文件夾如果不是圖片文件夾。我如何在php中實現此目的。有沒有辦法來比較?如果是的話怎麼辦?..誰能給這個如何在php中比較兩個不同的擴展文件?

感謝的想法提前

+2

用什麼方式比較?你已經知道這些文件有不同的內容。 – Joni 2013-03-22 07:15:44

+1

歡迎來到Stack Overflow!你有什麼嘗試?請張貼一些代碼。 – 2013-03-22 07:16:00

回答

0

它的基本。

<?php  
$ext= explode(".",$filename); // explode filename by "." 
$extension= $ext[1];// get extension. 
if($extension=="pdf") 
{ 
// do something 
} 
elseif($extension=="jpg" ||$extension=="png".....) 
{ 
// do something 
} 
?> 
+0

謝謝你的回答 – user2110147 2013-03-22 07:47:27

0

可以使用pathinfo()

<?php 
$file1 = pathinfo('file.pdf'); 
$file2 = pathinfo('file.jpg'); 

echo $file1['extension']; // will output pdf 
echo $file2['extension']; // will output jpg 
?> 
+0

謝謝你的回答 – user2110147 2013-03-22 07:50:54

0
$file1 = pathinfo($file1Path); 
$file2 = pathinfo($file2Path); 

if($file1['extension'] === $file2['extension']) { 
    //The extensions are the same. 
} 

if($file1['extension'] === 'pdf') { 
    //extensions is PDF and so on 
} 
+0

謝謝你的回答 – user2110147 2013-03-22 07:22:36

+0

@Ares ur bad,OP接受了一些elses的回答! – Vimalnath 2013-03-22 07:34:33

0
$fileExt = explode('.','yourFileWithExtension'); 
if($fileExt[1] == 'pdf') { 
    //move to attachments folder 
} else { 
    // some other folder 
} 
+0

謝謝你的回答 – user2110147 2013-03-22 07:46:47

+0

歡迎,upvote如果它幫助! – Vimalnath 2013-03-22 07:57:36

0
$file_extension = pathinfo("example.pdf", PATHINFO_EXTENSION) 
if ($file_extension == "jpg") { 
    your code here to send to image folder 
} else if ($file_extension == "pdf") { 
    your code here to send to attachments folder 
} 
+0

謝謝你的回答 – user2110147 2013-03-22 07:47:43

相關問題