Php code problems

Source: Internet
Author: User
Php code Problem 1. 2. $ id = isset ($ _ POST ['id'])? $ _ POST ['id']: 0;
3. $ filename = 'http: // saberlily-images.stor.sinaapp.com/'. strval ($ id). '.jpg ';
4. if (file_exists ($ filename )){
5. echo '';
6.} else {
7. echo '';
8 .}
9.?>


What is the problem with the code referenced by the filename function of Line 1 in this code ??? I changed the path to a local directory, but it was accessible.
But "the path to http://saberlily-images.stor.sinaapp.com/load.jpg is okay,
Because 7th rows can be accessed successfully.
Where is the problem?

Thank you!


Reply to discussion (solution)

File_exists can only check local files. you can use get_headers to obtain the header information remotely.

var_dump(file_exists('http://saberlily-images.stor.sinaapp.com/load.jpg'));

The value is false;
In other words, file_exists seems to be only used to judge the content under webroot.

$id = isset($_POST['id'])? $_POST['id'] : 0;$filename = 'http://saberlily-images.stor.sinaapp.com/load.jpg';if(getimagesize($filename)){echo '11';}else{echo '';}

'';
It is enclosed in single quotes and $ filename cannot be parsed.

File_exists is only applicable to files in local or network shared folders.

File_exists can only be judged? Local, sentence? Http does not work.

 


Http://cn2.php.net/file_exists

Judge ?? Can the process file exist ???
function check_remote_file($url){$result = get_headers($url, 1);if($result[0]=='HTTP/1.1 200 OK'){return true;}else{return false;}}$id = isset($_POST['id'])? $_POST['id'] : 0;$filename = 'http://saberlily-images.stor.sinaapp.com/' .strval($id). '.jpg';if(check_remote_file($filename)){    echo '';}else{   echo '';}

Now I can run it perfectly in Dream Weaver, but it is not displayed when I upload it to the SAE server. What is the situation?

Check the source code to see what is generated.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.