ERLEDIGT
NEIN
NEIN
ANTWORTEN
4
4
ZUGRIFFE
1832
1832
EMPFEHLEN
-
Hallo an Allllleeeee
Folgendes Problem:
WIe kann ich es realizieren, daß bei der Funktion Bild Upload, ein Standard NoPic Bild eingesetzt wird, wenn ein User kein Bild upgeloadet hat.
Ich habe jetzt schon einige Foren durchforstet und auch schon ein bissl selbst experimentiert, aber meine PHP Kenntnisse reichen wohl dafür nicht aus.
Ich vermute, dass man dazu die FALSE Abfrage verwendet, aber wie und wo baue ich sie ein?
Der Bildupload wird mit 2 Scripts erledigt.
1x das Formular "add.php"
Hier der Ausschnitt des Codes:
und upload_class.phpPHP-Code:if (C_CHECK_REGISTER == '0') $cst = 7;
elseif (C_CHECK_REGISTER == '2') $cst = 1;
else $cst = 0;
$picture = array('', '', '', '', '');
if ((C_PHOTOR) && ((empty($HTTP_POST_FILES['file0']['name'])) && (empty($HTTP_POST_FILES['file1']['name'])) && (empty($HTTP_POST_FILES['file2']['name'])) && (empty($HTTP_POST_FILES['file3']['name'])) && (empty($HTTP_POST_FILES['file4']['name'])))) $errors .= $w[41].'<br>';
if ($errors == '')
{
////////////// Include class for file uploading!
include_once 'classes/upload.class.php';
//////////////
$time = time();
for($p = 0; $p <= 4; $p++)
{
$file = 'file'.$p;
$k = $p+1;
if (!empty($HTTP_POST_FILES[$file]['name']))
{
if (!C_IMG_ERR)
{
// If Unavailable image upload errors with UIN
$dir = date("mY", $time);
$slash = "/";
if (!file_exists(C_PATH.'/members/uploads/'.$dir))
{
umask(0);
mkdir (C_PATH."/members/uploads/".$dir, 0777);
}
}
else $dir = $slash = "";
$fb = date("dHis", $time);
$fe = rand(0, 999);
$fn = $fb."-".$fe;
$intpic = $dir.$slash.$fn.'.';
$u = new Upload($file, C_MAXSZ, C_MAXWD, C_MAXHG, C_PATH.'/members/uploads/'.$intpic);
if (!$u->do_upload()) $errors .= $u->getErrors().'<br>';
$picture[$p] = $intpic.$u->getType();
}
}
mysql_query("INSERT INTO ".C_MYSQL_MEMBERS." VALUES ('','".$fname."','".$lname."','".$pass."',
'".$year."-".$month."-".$day."','".$gender."',
'".$purpose."','".$country."','".$email."','".$url."',
'".$icq."','".$aim."','".$phone."','".$city."','".$adres."','".$marstat."','".$child."','".$height."','".$weight."','".$hcolor."','".$ecolor."','".$etnicity."','".$religion."','".$smoke."','".$drink."','".$education."','".$job."','".$hobby."','".$descr."','".$sgender."','".$setnicity."','".$sreligion."','".$agef."','".$aget."','".$heightf."','".$heightt."','".$weightf."','".$weightt."','".$hdyfu."','".$picture[0]."','".$picture[1]."','".$picture[2]."','".$picture[3]."','".$picture[4]."','".horo($month, $day)."',NOW(''),NOW(''),INET_ATON('".ip()."'),'".$cst."','0')") or die(mysql_error());
$last_id = mysql_fetch_array(mysql_query("SELECT LAST_INSERT_ID() AS last_id"));
$last_id = $last_id['last_id'];
$codegen = code_gen();
if ((C_CHECK_REGISTER == '1') || (C_CHECK_REGISTER == '3'))
{
$str = $w[42];
mysql_query("INSERT INTO ".C_MYSQL_TEMP." VALUES ('".$last_id."',NOW(''),'".$codegen."')");
sendmail(C_ADMINM, $email, $w[43], $w[44].C_URL.'/check.php?id='.$last_id.'&code='.$codegen, 'text');
}
elseif(C_CHECK_REGISTER == '2')
{
$str = $w[45];
}
elseif(C_CHECK_REGISTER == '0')
{
if (C_ID == '2') $last_id = $email;
$str = $w[46].$last_id.$w[47].$pass;
}
printm($str);
}
else
{
mes($w[290].'<p align=left>'.$errors.'</p>');
}
}
?>
<script language="JavaScript">
<!--
function formCheck(form) {
<?if (C_FIRSTNR) {$tm=array(C_FIRSTNS,C_FIRSTNB);?>
if (form.fname.value == "")
{alert("<?=template($w[3],$tm)?>");return false;}
<?}?>
<?if (C_LASTNR) {$tm=array(C_LASTNS,C_LASTNB);?>
if (form.lname.value == "")
{alert("<?=template($w[4],$tm)?>");return false;}
<?}?>
if (form.pass.value == "")
<?$tm=array(C_PASSS,C_PASSB);?>
{alert("<?=template($w[6],$tm)?>");return false;}
if (form.rpass.value == "")
{alert("<?=$w[48]?>");return false;}
if (form.pass.value != form.rpass.value)
{alert("<?=$w[49]?>");return false;}
<?if (C_BIRTHR) {?>
if ((form.month.selectedIndex=="")||(form.day.selectedIndex=="")||(form.year.selectedIndex==""))
{alert("<?=$w[5]?>");return false;}
<?}?>
<?if (C_GENDR) {?>
if (form.gender.selectedIndex=="")
{alert("<?=$w[7]?>");return false;}
<?}?>
<?if (C_SGENDR) {?>
if (form.sgender.selectedIndex=="")
{alert("<?=$w[8]?>");return false;}
<?}?>
<?if (C_PURPR) {?>
if (form.purpose.selectedIndex=="")
{alert("<?=$w[9]?>");return false;}
<?}?>
<?if (C_CNTRR) {?>
if (form.country.selectedIndex=="")
{alert("<?=$w[10]?>");return false;}
<?}?>
if (form.email.value == "")
{alert("<?=$w[11]?>");return false;}
<?if (C_PHONER) {?>
if (form.phone.value == "")
{alert("<?=$w[15]?>");return false;}
<?}?>
<?if (C_CITYR) {?>
if (form.city.value == "")
{alert("<?=$w[16]?>");return false;}
<?}?>
//<?if (C_ADRESR) {?>
//if (form.adres.value == "")
//{alert("<?=$w[400]?>");return false;}
<?}?>
<?if (C_MARSR) {?>
if (form.marstat.selectedIndex=="")
{alert("<?=$w[17]?>");return false;}
<?}?>
<?if (C_CHILDR) {?>
if (form.child.selectedIndex=="")
{alert("<?=$w[18]?>");return false;}
<?}?>
<?if (C_HGHTR) {?>
if (form.height.selectedIndex=="")
{alert("<?=$w[19]?>");return false;}
<?}?>
<?if (C_WGHTR) {?>
if (form.weight.selectedIndex=="")
{alert("<?=$w[20]?>");return false;}
<?}?>
<?if (C_HAIRR) {?>
if (form.hcolor.selectedIndex=="")
{alert("<?=$w[23]?>");return false;}
<?}?>
<?if (C_EYER) {?>
if (form.ecolor.selectedIndex=="")
{alert("<?=$w[24]?>");return false;}
<?}?>
<?if (C_ETNR) {?>
if (form.etnicity.selectedIndex=="")
{alert("<?=$w[25]?>");return false;}
<?}?>
<?if (C_RELR) {?>
if (form.religion.selectedIndex=="")
{alert("<?=$w[26]?>");return false;}
<?}?>
<?if (C_SETNR) {?>
if (form.setnicity.selectedIndex=="")
{alert("<?=$w[27]?>");return false;}
<?}?>
<?if (C_SRELR) {?>
if (form.sreligion.selectedIndex=="")
{alert("<?=$w[28]?>");return false;}
<?}?>
<?if (C_SMOKER) {?>
if (form.smoke.selectedIndex=="")
{alert("<?=$w[29]?>");return false;}
<?}?>
<?if (C_DRINKR) {?>
if (form.drink.selectedIndex=="")
{alert("<?=$w[30]?>");return false;}
<?}?>
<?if (C_EDUCR) {?>
if (form.education.selectedIndex=="")
{alert("<?=$w[31]?>");return false;}
<?}?>
<?if (C_JOBR) {?>
if (form.job.value=="")
{alert("<?=$w[32]?>");return false;}
<?}?>
<?if (C_HOBBR) {?>
if (form.hobby.value=="")
{alert("<?=$w[35]?>");return false;}
<?}?>
if (form.descr.value=="")
{alert("<?=$w[38]?>");return false;}
<?if (C_HDYFUR) {?>
if (form.hdyfu.selectedIndex=="")
{alert("<?=$w[34]?>");return false;}
<?}?>
<?if (C_PHOTOR) {?>
if ((form.file0.value=="")&&(form.file1.value=="")&&(form.file2.value=="")&&(form.file3.value=="")&&(form.file4.value==""))
{alert("<?=$w[41]?>");return false;}
<?}?>
if (document.form.submit.action != "") {
document.form.submit.disabled=1;}
}
// -->
</script>
PHP-Code:
<?
class Upload {
var $up_file;
var $f;
var $p;
var $name;
var $size;
var $widht;
var $height;
var $type;
var $max_size;
var $path;
var $directory;
var $errors;
var $move;
function Upload($input_name,$size,$width,$height,$dir) {
$this->f = $input_name;
$this->max_size = $size;
$this->directory = $dir;
$this->max_width = $width;
$this->max_height = $height;
}
function do_upload() {
//global $_FILES;
$this->up_file = $_FILES[$this->f]['tmp_name'];
$this->name = $_FILES[$this->f]['name'];
$this->size = $_FILES[$this->f]['size']/1000;
$this->type = $_FILES[$this->f]['type'];
if (ereg(".gif$", $this->type)) $this->type="gif";
elseif(ereg(".png$", $this->type)) $this->type="png";
elseif(ereg(".jpg$", $this->type)||
ereg(".jpeg$", $this->type)) $this->type="jpg";
else $this->type="";
$this->path = $this->directory;
$this->width = $this->height = '';
if(!empty($this->up_file)&&(C_HACK3)) {
$this->p = getimagesize($this->up_file);
$this->width = $this->p[0];
$this->height = $this->p[1];
}
$this->errors = '';
if($this->move_file()) return true;
else return false;
}
function getName() {
return $this->name;
}
function getMaxSize() {
return $this->max_size;
}
function getSize() {
return $this->size;
}
function getType() {
return $this->type;
}
function move_file() {
if($this->check_size() && $this->check_extension() && $this->check_uploaded() && $this->check_wh()) {
$this->move = move_uploaded_file($this->up_file, $this->path.$this->type);
chmod($this->path.$this->type, 0644);
return true;
} else {
return false;
}
}
function check_size() {
global $w;
if(($this->up_file != "")&&($this->size <= $this->max_size)) {
return true;
} else {
if($this->errors == '') {
$tm=array($this->max_size,$this->size);
$this->errors = $this->errors.template($w[220],$tm);
}
return false;
}
}
function check_wh() { // Check width and height
global $w;
if(($this->up_file != "")&&($this->width <= $this->max_width)&&($this->height <= $this->max_height)) {
return true;
} else {
if($this->errors == '') {
$tm=array($this->max_width,$this->max_height);
$this->errors = $this->errors.template($w[2201],$tm);
}
return false;
}
}
function check_uploaded() {
global $w;
if(is_uploaded_file($this->up_file)) {
return true;
} else {
if($this->errors == '') {
$this->errors = $this->errors.$w[1].'4';
}
return false;
}
}
function check_extension() {
global $w;
if ($this->type == "") {
if($this->errors == '') {
$this->errors = $this->errors.$w[222].$this->type;
}
return false;
} else {
return true;
}
}
function getErrors() {
return $this->errors;
}
}
?>
Vielleicht hat jemand einen Tipp, würde mich sehr freuen.
Danke im Voraus
George
-
Hi nochmal
Blödsinn, was im Vorbeitrag geschrieben habe
War im Lösungswahn
und mit den Gedanken woanders.
Habe euch den falschen Code gepostet.
Add.php erledigt natürlich den Upload, dem ist ja egal ob ein Bild upgeloadet wird oder nicht.
Auf der Startseite werden Bilder angezeigt und dort soll erkannt werden, ob ein Bild in der DB vorhanden ist oder nicht.
Wenn nicht dann soll es mit keinbild.jpg erstetzt werden.
Hier ist das Stück, daß die Bild Anzeige erledigt.
in meinem alten Script war das so gelöst:PHP-Code:<table width="100%" class=tr>
<tr class=mes bgcolor="<?=COLORH?>" align=center><td><?=$w[118]?></td><td><?=$w[132]?></td><td><?=$w[120]?></td><td><?=$w[87]?></td></tr>
<?$tmp=mysql_query("SELECT id, fname, gender, birthday, pic1, pic2, pic3 FROM ".C_MYSQL_MEMBERS." WHERE status >= '7' order by regdate DESC limit ".C_LASTREG);
$color='';
while($i=mysql_fetch_array($tmp)) {
$color = ($color == COLOR4) ? COLOR3 : COLOR4;
$name = (trim($i['fname']) == '') ? $i['id'] : $i['fname'];
$ph = (($i['pic1'] == '')&&($i['pic2'] == '')&&($i['pic3'] == '')) ? $w[111] : $w[112];
$photo = (trim($i['pic1']) == '') ? $i['id'] : $i['pic1'];
$age=abs(mysql2data($i['birthday'],1));
echo "<tr class=desc bgcolor=\"".$color."\" align=center><td><a href=\"view.php?l=".$l."&id=".$i['id']."\" class=desc>".$name."</a></td><td>".$wg[$i['gender']]."</td><td>".$age."</td><td><a href=\"view.php?l=".$l."&id=".$i['id']."\" class=desc><img src=members/uploads/".$photo." width=\"40\" border=\"0\"></td></tr>";}
$tmp=mysql_query("SELECT count(id) as total FROM ".C_MYSQL_MEMBERS." WHERE status >= '7'");
$rows=mysql_fetch_array($tmp);$usc=$rows['total'];?>
</table>
Da war das noch einfach, aber nun, keine AhnungPHP-Code:$test=mysql_query("select * from boydaten where id='$id'");
$testen=mysql_fetch_array($test);
if($testen[geschlecht]=="m")
{
$geschlecht="männlich";
}
if($testen[geschlecht]=="w")
{
$geschlecht="weiblich";
}
if($testen[geschlecht]=="u")
{
$geschlecht="undefiniert";
}
if(!strstr($testen[bildurl], "http://" ) && !strstr($testen[bildurl], "bilder" ))
{
$bildurl="bilder/$testen[bildurl]";
}
else
{
$bildurl=$testen[bildurl];
}
if($testen[bildurl]!="bilder/keinbild.jpg")
{
$bildtext="<a href='$bildurl' target=_blank><img src='herz.gif' border=0></a>";
}
else
{
$bildtext="<img src='herz2.gif' border=0>";
}
if($testen[bildurl]=="")
{
$bildtext="<img src='herz2.gif' border=0>";
}
George
-
Ohne jetzt deinen gesamten Code zu studieren...
Lasse einfach nichts in die DB eintragen und in der Ausgabe fragst du ab, ob das Feld leer ist und im erfolgsfall lässt dann das NoPic-Bild ausgeben.
So mache ich das zumindest
-
Hallo
Ich weiss nicht ob mein Gedankengut in richtiger Richtung geht.
Ich denke si, ist ein Bild zum Upload vorhanden, wird es upgeloadet mit der Funktion:
ist kein Bild vorhanden soll es einfach durch eine Standarddatei ersetzt werden in dem Fall z.B. "keinbild.jpg"PHP-Code:// If Unavailable image upload errors with UIN
$dir = date("mY", $time);
$slash = "/";
if (!file_exists(C_PATH.'/members/uploads/'.$dir))
{
umask(0);
mkdir (C_PATH."/members/uploads/".$dir, 0777);
}
}
else $dir = $slash = "";
$fb = date("dHis", $time);
$fe = rand(0, 999);
$fn = $fb."-".$fe;
$intpic = $dir.$slash.$fn.'.';
$upl = new Upload($file, C_MAXSZ, C_MAXWD, C_MAXHG, C_PATH.'/members/uploads/'.$intpic);
if (!$upl->do_upload()) $errors .= $upl->getErrors().'<br>';
$picture[$p] = $intpic.$upl->getType();
}
}
Mit der obigen funktion wird erkannt, wenn kein Bild vorhanden ist und ein upolad ignoriert, auf der Bildvorschau Seite wird dann jedoch ein hässliches kleins Rechteck ausgegeben und als Bildname wird in der Bildurl die Datensatznummer ausgegeben, z.B.
members/uploads/00642
Beim erfolgreichen Upload wird ein Bild automatisch umbenannt und mit einem Zufallsnamen/ Zahl versehen z.B. members/uploads/10043658-149.jpg
Ich habe bis jetzt in dieser Richtung experimentiert,
weiss aber nicht ob es so richitg ist und wie es dann weiter geht....PHP-Code:$nopic = "keinbild.jpg";
$dir_no = $nopic = "";
if (!file_no_exists(C_PATH.'/members/uploads/'.$dir_no)) return false;
Ausserdem bekomme ich beim Datensatz Eintrag dann eine Fehlermeldung
>>> Fatal error: Call to undefined function: file_no_exists() in /homepages/38/d13424084/htdocs/of/kontakt/add.php on line 197
<<<
Ist ja auch klar, weil da eine Funktion fehlt
Oder liege ich hier TOTAL FATAL FALSCH
Hier ist nochmal der Code der ganzen Sektion
Ihr könnt euch das auch live ansehen unterPHP-Code:////////////// Include class for file uploading!
include_once 'classes/upload.class.php';
//////////////
$time = time();
for($p = 0; $p <= 2; $p++)
{
$file = 'file'.$p;
$k = $p+1;
if (!empty($HTTP_POST_FILES[$file]['name']))
{
if (!C_IMG_ERR)
{
// If Unavailable image upload errors with UIN
$dir = date("mY", $time);
$slash = "/";
if (!file_exists(C_PATH.'/members/uploads/'.$dir))
{
umask(0);
mkdir (C_PATH."/members/uploads/".$dir, 0777);
}
}
else $dir = $slash = "";
$fb = date("dHis", $time);
$fe = rand(0, 999);
$fn = $fb."-".$fe;
$intpic = $dir.$slash.$fn.'.';
$upl = new Upload($file, C_MAXSZ, C_MAXWD, C_MAXHG, C_PATH.'/members/uploads/'.$intpic);
if (!$upl->do_upload()) $errors .= $upl->getErrors().'<br>';
$picture[$p] = $intpic.$upl->getType();
}
}
$nopic = "keinbild.jpg";
$dir_no = $nopic = "";
if (!file_no_exists(C_PATH.'/members/uploads/'.$dir_no)) return false;
if ($errors == '')
{
mysql_query("INSERT INTO ".C_MYSQL_MEMBERS." VALUES ('','".$fname."','".$lname."','".$pass."',
'".$year."-".$month."-".$day."','".$gender."',
'".$purpose."','".$country."','".$email."','".$url."',
'".$icq."','".$aim."','".$phone."','".$city."','".$adres."','".$marstat."','".$child."','".$height."','".$weight."','".$hcolor."','".$ecolor."','".$etnicity."','".$religion."','".$smoke."','".$drink."','".$education."','".$job."','".$hobby."','".$descr."','".$sgender."','".$setnicity."','".$sreligion."','".$agef."','".$aget."','".$heightf."','".$heightt."','".$weightf."','".$weightt."','".$hdyfu."','".$picture[0]."','".$picture[1]."','".$picture[2]."','".$picture[3]."','".$picture[4]."','".horo($month, $day)."',NOW(''),NOW(''),INET_ATON('".ip()."'),'".$cst."','0')") or die(mysql_error());
http://www.ostfrauen.de/kontakt/index.php
-
Geh ich richtig in der Annahme dass die upload_class.php bzw. die darin befindliche
Klasse nicht deine Kreation ist?!
Wenn du dich selber mir dem Problem beschäftigst findest du selber schnell
eine entsprechende Lösung
`
OT: Ich überleg grad wofür man bei einem Upload eine extra Klasse benötigt.»
Ähnliche Themen
-
Ersatzbild wenn kein Bild vorhanden
Von thommy1972 im Forum PHPAntworten: 3Letzter Beitrag: 10.10.10, 11:31 -
Prüfen ob Link-Bild vorhanden ist, wenn nicht Bild auf Server löschen?
Von ilmer im Forum PHPAntworten: 13Letzter Beitrag: 23.01.09, 00:14 -
Textzeilen in Wordvorlage löschen, wenn kein Einlesetext vorhanden
Von ISIPI im Forum Visual Basic 6.0Antworten: 2Letzter Beitrag: 25.02.08, 10:46 -
Hinweis wenn kein Datensatz vorhanden
Von redwing78 im Forum ASPAntworten: 7Letzter Beitrag: 10.08.05, 07:52 -
wenn kein datensatz vorhanden, dann ...
Von eugster im Forum PHPAntworten: 3Letzter Beitrag: 09.03.05, 11:36





Zitieren
Login






[PHP][Snippet] Array zu XML konvertieren