/ / file_exists (…) funktioniert nicht in WordPress - PHP, WordPress

file_exists (…) funktioniert nicht in WordPress - PHP, WordPress

Versuchen zu verwenden file_exists() Funktion in WordPress, aber nicht erwartetes Ergebnis zu erhalten.

if(file_exists(WP_PLUGIN_URL."/sinetiks-schools/images/t_1.jpg")){
echo "ok";
} else {
echo "not";
}

Antworten:

1 für die Antwort № 1

Versuchen Sie, diesen zu verwenden. Ich hoffe, Ihr Problem wird gelöst

    $image = get_template_directory() . "/images/" . get_the_title() . ".png";
$image2 = get_template_directory_uri() . "/images/" . get_the_title() . ".png";

if (file_exists($image))
{
echo "<img src="/images/ . $image2 . ">";
}
else
{
echo the_title("<h1 class="title">","</h1>");
}

0 für die Antwort № 2

Du solltest es versuchen:

if(file_exists(plugin_dir_path( __FILE__ )."/sinetiks-schools/images/t_1.jpg")){

}

Stellen Sie sicher, dass Sie den richtigen Pfad von erhalten plugin_dir_path( __FILE__ )

Weitere Informationen zur Funktion plugin_dir_path finden Sie hier Hier