Thanks Steve - it's almost working - I even thought it was
working at first - file name is dropping nicely into the file_name
field - just the name without the path which is perfect.
But the files don't seem to be uploading now. I've probably
just got some things wrongly named, but I've been trying everything
without success.
At the moment I have a file upload page that looks like :
<?php require_once('Connections/Photolibrary.php'); ?>
<?php
function GetSQLValueString($theValue, $theType,
$theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ?
addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" :
"NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) .
"'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" :
"NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue :
$theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" .
htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) &&
($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO photos (Photo_File) VALUES
(%s)",
GetSQLValueString($_FILES['file']['name'], "text"));
mysql_select_db($database_Photolibrary, $Photolibrary);
$Result1 = mysql_query($insertSQL, $Photolibrary) or
die(mysql_error());
$insertGoTo = "fileuploaded.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_Photolibrary, $Photolibrary);
$query_Recordset1 = "SELECT * FROM photos";
$Recordset1 = mysql_query($query_Recordset1, $Photolibrary)
or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "
http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form name="form1" action="<?php echo $editFormAction;
?>" method="POST" enctype="multipart/form-data">
Type (or select) Filename: <input type="file"
name="file">
<input type="hidden" name="MAX_FILE_SIZE" value="25000"
/> <input type="submit" value="Upload file">
<input type="hidden" name="MM_insert" value="form1">
</form>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
And a fileuploaded.php page that looks like :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "
http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<?php
move_uploaded_file ($_FILES['file'] ['tmp_name'],
"Photos/{$_FILES['file'] ['name']}")
?>
File uploaded
</body>
</html>
Where 'file' is the name of the file upload field in the
first page.
Any ideas?
Iain