Forums
This topic is locked
What's wrong
Posted 05 Dec 2002 14:09:47
1
has voted
05 Dec 2002 14:09:47 Tommi Virtanen posted:
Hi!I've a update form. So it's has for example name -field (i can update it using standard MX string:
GetSQLValueString($HTTP_POST_VARS['name'], "text"
But i have also 'file field' type field, which (i should) update data into db, and also upload file-size. But how can do it. Following doesn't work!
GetSQLValueString($addslashes(fread(fopen($form_data, "r"), "text"),
GetSQLValueString($addslashes(fread(filesize($form_data)), "text" )));
----------
gustavus
Replies
Replied 14 Jan 2003 15:46:07
14 Jan 2003 15:46:07 Nicholas Bennett replied:
hi,
i've written you an example of how to handle file uploads ... i strongly suggest you go and read the php manual and look at file uploads!! but i've included as much documentation as i can to explain what the script is doing. Here it is ... <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
FIRST HERE IS THE HTML FORM WITH THE FILE UPLOAD FIELD
------------------------------------
<#h1>Upload a File</h1>
<#!-- Note: The form must have the enctype set like this!! ->
<#form enctype="multipart/form-data" method="post" action="upload.php">
File to Upload:
<#!-- Note: The name="userfile" in the file input, is how we refer to the uploaded file in the upload.php script example: $_FILES['userfile'] ->
<#input type="file" name="userfile" size="30">
<#input type="submit" name="submit" value="Upload File">
<#/form>
this forum has html code active so replace the # above
SECOND, HERE IS THE PHP SCRIPT TO PROCESS AND RETURN INFO RELATING TO THE FILE
--------------------------------------
<?
####
# Author: Nicholas Bennett
# Filename: upload.php
# Description: A simple example of Handling file uploads
####
/**
* load()
* A function to open and read the entire contents of a file
* @param $filename
* @return contents of $filename on sucess or kill script and display message on error
*/
function load($filename)
{
// Open for reading only; place the file pointer at the beginning of the file.
$fp = @fopen($filename, "rb"
if($fp)
{
// File was sucessfully opened so read the contents
$file = @fread($fp, filesize($filename));
// Close the file pointer
@fclose($fp);
return $file;
}
else
{
// Could not open a file pointer
die("Could not open file."
}
}
if ($_FILES['userfile'] != ""
{
// A file was uploaded..
// so, open and return the contents into the var $uploaded_file_contents
$uploaded_file_contents = load($_FILES['userfile']['tmp_name']);
$uploaded_file_name = $_FILES['userfile']['name'];
$uploaded_file_size = $_FILES['userfile']['size'];
// Debug
echo("Filename: ".$uploaded_file_name."<br>\n"
echo("Size: ".$uploaded_file_size."<br>\n"
echo("Contents:<br>\n".$uploaded_file_contents);
}
else
{
// if $_FILES['userfile'] was empty, display an error
die("No input file specified"
}
?>
Edited by - nickuk on 14 Jan 2003 15:52:06
Edited by - nickuk on 14 Jan 2003 16:18:40
i've written you an example of how to handle file uploads ... i strongly suggest you go and read the php manual and look at file uploads!! but i've included as much documentation as i can to explain what the script is doing. Here it is ... <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
FIRST HERE IS THE HTML FORM WITH THE FILE UPLOAD FIELD
------------------------------------
<#h1>Upload a File</h1>
<#!-- Note: The form must have the enctype set like this!! ->
<#form enctype="multipart/form-data" method="post" action="upload.php">
File to Upload:
<#!-- Note: The name="userfile" in the file input, is how we refer to the uploaded file in the upload.php script example: $_FILES['userfile'] ->
<#input type="file" name="userfile" size="30">
<#input type="submit" name="submit" value="Upload File">
<#/form>
this forum has html code active so replace the # above
SECOND, HERE IS THE PHP SCRIPT TO PROCESS AND RETURN INFO RELATING TO THE FILE
--------------------------------------
<?
####
# Author: Nicholas Bennett
# Filename: upload.php
# Description: A simple example of Handling file uploads
####
/**
* load()
* A function to open and read the entire contents of a file
* @param $filename
* @return contents of $filename on sucess or kill script and display message on error
*/
function load($filename)
{
// Open for reading only; place the file pointer at the beginning of the file.
$fp = @fopen($filename, "rb"
if($fp)
{
// File was sucessfully opened so read the contents
$file = @fread($fp, filesize($filename));
// Close the file pointer
@fclose($fp);
return $file;
}
else
{
// Could not open a file pointer
die("Could not open file."
}
}
if ($_FILES['userfile'] != ""
{
// A file was uploaded..
// so, open and return the contents into the var $uploaded_file_contents
$uploaded_file_contents = load($_FILES['userfile']['tmp_name']);
$uploaded_file_name = $_FILES['userfile']['name'];
$uploaded_file_size = $_FILES['userfile']['size'];
// Debug
echo("Filename: ".$uploaded_file_name."<br>\n"
echo("Size: ".$uploaded_file_size."<br>\n"
echo("Contents:<br>\n".$uploaded_file_contents);
}
else
{
// if $_FILES['userfile'] was empty, display an error
die("No input file specified"
}
?>
Edited by - nickuk on 14 Jan 2003 15:52:06
Edited by - nickuk on 14 Jan 2003 16:18:40
Replied 23 Aug 2006 08:34:09
23 Aug 2006 08:34:09 LorD ExoskeletoN replied:
guys... im just a newbie...can you help me in my problem on how to upload file and save it to database?