ok, here comes the whole code:
<?php
// pick a file extension
if (eregi('îmage/p?jpeg(;.*)?$',
$_FILES['uploadedfile']['type']) )
$extension = '.jpg';
else $extension = '.gif';
// the complete path/filename
if ($_FILES['uploadedfile']['name'] == "")
{
$filename = "images/1x1.gif";
}else{
$filename = "images/" . time() . $_FILES['uploadedfile']['name'];
}
// Copy the file
if (is_uploaded_file($_FILES['uploadedfile']['tmp_name']) and
copy($_FILES['uploadedfile']['tmp_name'], $filename)) {
echo("<p>File stored successfully as $filename.</p>");
}else{
echo("<p>Could not save as $filename.</p>");
}
echo($_FILES['userfile']['error']);
if ($submit): // Eine neue nachricht wurde in das Formular eingetragen
if ($aid == "") {
echo("<p>du müsset für diesee nachricht " .
"einen Autor auswählen. Klicke auf 'Zurück' " .
"und probiere es nochmal.</p>");
exit();
}
// datenbank auswaehlen
$dbcnx = mysql_connect("db******", "*****", "*******");
if (!$dbcnx) {
echo( "<p>Zur Zeit keine Verbindung " .
"zum Datenbankserver möglich.</p>" );
exit();
}
// news datenbank auswaehlen
if (! mysql_select_db("db*******") ) {
echo( "<p>Auswahl der NEWS-Datenbank " .
"zur Zeit nicht möglich.</p>" );
exit();
}
$sql = "INSERT INTO news SET
newshead='$newshead',
newstext='$newstext',
URL='$URL',
image='$filename',
newsdate=CURDATE(),
AID='$aid'";
if (@mysql_query($sql)) {
//echo("<p>New message added</p>");
} else {
echo("<p>error while adding: " .
mysql_error() . "</p>");
}
$jid = mysql_insert_id();
if ($cats == "") $cats = array();
foreach ($cats as $catID) {
$sql = "INSERT IGNORE INTO newslookup
SET NID=$jid, CID=$catID";
$ok = @mysql_query($sql);
if ($ok) {
$numCats = $numCats + 1;
} else {
echo("<p>Fehler beim Einfügen der Nachricht in die Kategorie $catID: " .
mysql_error() . "</p>");
}
}
?>
so, this example works.
I have thought about just to change this part:
// the complete path/filename
if ($_FILES['uploadedfile']['name'] == "")
{
$filename = "images/1x1.gif";
}else{
$filename = "images/" . time() . $_FILES['uploadedfile']['name'];
}
into this:
// the complete path/filename
if ($_FILES['uploadedfile']['name'] == "")
{
$filename = "images/1x1.gif";
}else{
$filename = "images/news/" . time() . $_FILES['uploadedfile']['name'];
}
but if I do so ( or change to any other path, including absolut paths) the image is not saved and I got an error message, like:
Could not save as /2003/images/news/1093204433imm012.jpg.
means the name in the table is saved properly (what I wrote in my previously posted message about strange path names was wrong, my fault), but not the image itself to the specified folder.
thanks a lot (und gruesse nach karlsruhe and its ISPs)
stephan