How can I replace the picture, if it does not exist, either in the database (the image field is empty) or in the folder with photos ../uploads/ in php ?
Php code:
<?php $query_art = mysql_query("SELECT * FROM `news`");?> <?php for($i = 0; $i < mysql_num_rows($query_art); ++$i): ?> <?php $array = mysql_fetch_array($query_art); ?> <?php $ar_image = $array['image']; ?> <?php if (!empty($ar_image)){ $image = $ar_image; } else { $image = "none_foto.png"; } ?> <img alt="Фото" src="../uploads/<?php echo $image; ?>" class="leftimg" /> <?php endfor; ?>
const UPLOAD_FOLDER = "../uploads/"; const IMAGES_FOLDER = "images";const UPLOAD_FOLDER = "../uploads/"; const IMAGES_FOLDER = "images";and then just substitute that constant, depending on the case ....... a la$image = (!empty($ar_image)) ? UPLOAD_FOLDER.$ar_image : $image = IMAGES_FOLDER."none_foto.png";$image = (!empty($ar_image)) ? UPLOAD_FOLDER.$ar_image : $image = IMAGES_FOLDER."none_foto.png";....... in theimgtag it will just be already<img alt="Фото" src="<?= $image; ?>" class="leftimg" />- Aleksey Shimanskyview, then in the class you need to make constants that you declare once and then use them repeatedly. In the case ofIMAGES_FOLDER, the good thing is to be stored in the applicationdefine('ИМЯ_КОНСТАНТЫ', значение)asdefine('ИМЯ_КОНСТАНТЫ', значение).. and then you can simply use it through the nameecho ИМЯ_КОНСТАНТЫ.. in class viaconst ИМЯ_КОНСТАНТЫ = значение;and then the use is as follows:echo ИмяКласса::ИМЯ_КОНСТАНТЫ;in your code how to use I wrote. + Do not forgetfile_existsasfile_existswrote - Alexey Shimansky