Forum Moderators: coopster
$target_path = "/var/www/html/artists/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$image_path = $_FILES['uploadedfile']['name'];
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded<br>\n";
}
if($submit)
{//begin of if($submit).
// Set global variables
$bandname = $_POST['bandname'];
$member1 = $_POST['member1'];
$member2 = $_POST['member2'];
$member3 = $_POST['member3'];
$member4 = $_POST['member4'];
$member5 = $_POST['member5'];
$member6 = $_POST['member6'];
$member7 = $_POST['member7'];
$member8 = $_POST['member8'];
$description = $_POST['description'];
$website_url = $_POST['website_url'];
$image_path = $_POST['target_path'];
//add automatic line breaks
$description = ereg_replace(13,"<p>",$description);
//run the query which adds the data gathered from the form into the database
$result = mysql_query("INSERT INTO artists (bandname, dtime, member1, member2, member3, member4, member5, member6, member7, member8, description, website_url, image_path)
VALUES ('$bandname',NOW(),'$member1','$member2','$member3','$member4','$member5','$member6','$member7','$member8','$description','$website_url','$target_path')",$connect);
//print success message.
echo "<b>Artist added successfully!<br>You'll be redirected to the control panel after (4) seconds, or click <a href=\"index.php\">click here</a> to go there now.\n";
echo "<meta http-equiv=Refresh content=4;url=index.php>";
}//end of if($submit)
Can anyone tell me why the image uploads, and it saves the path to the db, but without the filename attached? I've been staring at this for too long :(
Thanks in advance for the extra eyes,
gen
=====
<?php
include("../config.php");
if($submit) {
if (!empty($_FILES['uploadedfile']['name'])){
//file upload processing here, only runs if someone chose another img
$target_path = "/var/www/html/artists/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if (file_exists($target_path) and!is_dir($target_path)){
//if file exists and file is not a directory...
unlink($target_path);
}
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)){
echo "The file <strong>". basename( $_FILES['uploadedfile']['name']). "</strong> has been uploaded<br><br>\n";
chmod("$target_path", 0777);
$image_entry = mysql_real_escape_string($_FILES['uploadedfile']['name']);
$result = mysql_query("UPDATE artists SET image_path='$image_entry' WHERE artistid='$artistid' ",$connect);
}
}
$bandname = mysql_real_escape_string($_POST['bandname']);
$description = mysql_real_escape_string($_POST['description']);
$website_url = mysql_real_escape_string($_POST['website_url']);
//add automatic line breaks
$description = ereg_replace(13,"<p>",$description);
//get ride of slashes
$description = stripslashes($description);
$bandname = stripslashes($bandname);
$result = mysql_query("UPDATE artists SET bandname='$bandname', description='$description', website_url='$website_url' WHERE artistid='$artistid' ",$connect);
echo "<b>Artist updated successfully!<br>You'll be redirected to the control panel after (4) seconds, or click <a href=\"index.php\">click here</a> to go there now.\n";
echo "<meta http-equiv=Refresh content=4;url=index.php>";
} elseif($artistid) {
$result = mysql_query("SELECT * FROM artists WHERE artistid='$artistid' ",$connect);
while($myrow = mysql_fetch_assoc($result))
{
$bandname = $myrow["bandname"];
$description = $myrow["description"];
$website_url = $myrow["website_url"];
$image_path = $myrow["image_path"];
?>
<br>
<h3>::Edit Artist</h3>
<form enctype="multipart/form-data" action="<?php echo $PHP_SELF?>" method="POST">
<p>Please be careful not to delete any line break or paragraph break tags shown as <strong><p></strong> or <strong><br></strong>.<br>
These are paragraph formatting tags that have been dynamically generated by this software.</p>
<p>
<input type="hidden" name="artistid" value="<? echo $myrow['artistid']?>">
<p>Band Name:<br>
<input name="bandname" size="40" maxlength="255" value="<?php echo $bandname;?>">
<br>
<br>
<p>Artist Image:<br>
<br>
<img src="../../artists/<?php echo $image_path;?>" title="<?php echo $bandname;?>">
<br>
<br>
Image File (required):<br />
<input type="file" name="uploadedfile">
<br>
<br>
Description:<br>
<textarea name="description" rows="7" cols="30"><?php echo $description;?></textarea>
<br>
<br>
Website URL: (with [)...] <br>
<input name="website_url" size="40" maxlength="255" value="<?php echo $website_url;?>">
<br>
<br>
<input type="submit" name="submit" value="Edit Artist >>">
<br>
<a href="index.php"><-- Go Back</a> </p>
</p>
</form>
<?
}//end of while loop
}//end else
?>
=====================
I really appreciate your help - you really pulled me out of this slump. :) Wish I could repay you somehow - let me know and I'll try and help if you need it.
Thanks again!