如何获得PDF或DOC文件大小?

时间:2016-07-18 09:55:18

标签: php

尝试获取pdf文档文件大小,但它给了我Warning: filesize(): stat failed for ...

我尝试过:

    //get original temporary name
    $temp_name = $_FILES['userDegreeFile']['tmp_name'];

    //original file path with original name
    $inital_name = $_SERVER['DOCUMENT_ROOT'] . "super/IMG/user_files/user_files_".$userFirstName."_".$user_id."/" . $temp_name; 

    //get the file size
    $file_size = filesize($inital_name);

运行时,我得到上述错误。错误中的文件名是D:/Programs/wamp/www/super/IMG/user_files/user_files_Jim_52/D:\Programs\wamp\tmp\php70B9.tmp

我做错了什么?

2 个答案:

答案 0 :(得分:2)

始终使用 <plugin> <groupId>org.codehaus.cargo</groupId> <artifactId>cargo-maven2-plugin</artifactId> <version>1.4.19</version> <configuration> <container> <containerId>tomcat8x</containerId> <type>remote</type> </container> <configuration> <type>runtime</type> <properties> <cargo.hostname>localhost</cargo.hostname> <cargo.servlet.port>9990</cargo.servlet.port> <cargo.remote.username>user</cargo.remote.username> <cargo.remote.password>pass</cargo.remote.password> </properties> </configuration> <deployer> <type>remote</type> </deployer> </configuration> </plugin> ,它兼容linux和windows路径。

DIRECTORY_SEPARATOR

另一种方式是$inital_name = $_SERVER['DOCUMENT_ROOT'] . "super".DIRECTORY_SEPARATOR."IMG".DIRECTORY_SEPARATOR."user_files".DIRECTORY_SEPARATOR."user_files_".$userFirstName."_".$user_id.DIRECTORY_SEPARATOR."$temp_name; 点击此处查看更多信息:How to use $_FILES["file"]["size"]?

答案 1 :(得分:0)

请试试这个我认为这会对你有所帮助

`

//输出,例如somefile.txt:1024字节

$ filename =&#39; somefile.txt&#39 ;; echo $ filename。 &#39;:&#39; 。 filesize($ filenam`)。 &#39;字节&#39 ;;

&GT?; `