here is an upload script im trying to write for a profile system i eventually want to write for my company. I am getting the else state “file could not be moved.” THis is my first upload script so im iffy on some things. Im not sure if im doing the file move code correctly, especially the path to the upload directory. Do i make the path relative to the upload script or to the root of the website directory? Anyways, here is my code.
<?php
session_start();
if(!isset($_SESSION['firstname'])){
header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/index.php");
exit();
}
//Checking form
if(isset($_POST['Submit'])){
//Connect to database
require_once ('connect2.php');
$query = "UPDATE members SET image='{$_FILES['upload']['name']}' WHERE id='{$_SESSION['id']}'";
$result = mysql_query($query);
if($result){
//creatE filename
$extension = explode ('.', $_FILES['upload']['name']);
$uid = mysql_insert_id();
$filename = $uid . '.' . $extension[1];
if(move_uploaded_file($_FILES['upload']['tmp_name'], "/uploads")){
echo '<p>picture upload correctly</p>';
}else{
$query = "UPDATE members SET image='NULL' WHERE id='{$_SESSION['id']}'";
$result = mysql_query($query);
echo '<p>file could not be moved</p>';
}
}else{
echo 'System Error';
}
mysql_close();
}
?>