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.