HI,
assuming you know the tutorial EXT: Form Extension Tutorial ( http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=602&cHash=2487fed4b2 ) I would like to discuss how it can be changed that way you can have an imageupload in the Database
(this topis is discussed here: http://www.phpbuilder.com/columns/florian19991014.php3?page=1
The challenge I try to reach is, that you can have a form where certain members can create their profile und upload their photo, further every member should be able to view the whole memberlist with the provided informations/photos....
I have to say, that I am quite new to TYPO and/but have a good understanding of PHP in general
I would like to use this space to develop/discuss this piece of code as I guess it would be very welcome to the typo community in general.....
Again, I followed the tutorial about form extension.....than changed the pi1/class.tx_matthimember_pi1.php....
for a better reading, I will post this code as a reply....just in front, THIS WAY IT DOESNT WORK !
So, but maybe this all can serve as a startingpoint to get the topic FILE UPLOAD WITH FORMS IN TYPO solved....
And just for curiosity: maybe I have missed something and something similar is out there, than you are very welcome to keep me up-to-date
P.S. mein english is zwar auch net das beste, aber ich würde mich freuen, wenn möglichst viele hier diskutieren können, deswegen in english...ich geh mal davon aus, dass hier jeder schon mal ein buch in english gelesen hat 😉
<?PHP
//......
require_once(PATH_tslib."class.tslib_pibase.php");
class tx_matthimember_pi1 extends tslib_pibase {
var $prefixId = "tx_matthimember_pi1"; // Same as class name
var $scriptRelPath = "pi1/class.tx_matthimember_pi1.php"; // Path to this script relative to the extension dir.
var $extKey = "matthi_member"; // The extension key.
/**
* [Put your description here]
*/
function main($content,$conf) {
$this->conf=$conf;
$this->pi_setPiVarDefaults();
$this->pi_loadLL();
if(isset ($this->piVars['submit_button'])) {
// WHAT TO DO if content is submitted
// t3lib_div::debug($this->piVars);
$data = addslashes(fread(fopen($foto, "r")));
$query = 'INSERT INTO tx_matthimember_table (vname,nname,firma,position,phone,mail,foto,pid)
VALUES("'.addslashes($this->piVars['DATA']['vname']).'",
"'.addslashes($this->piVars['DATA']['nname']).'",
"'.addslashes($this->piVars['DATA']['firma']).'",
"'.addslashes($this->piVars['DATA']['position']).'",
"'.addslashes($this->piVars['DATA']['phone']).'",
"'.addslashes($this->piVars['DATA']['mail']).'",
"'.addslashes($this->piVars['FILE']['data']).'",
"'.$GLOBALS['TSFE']->id.'")';
$res = mysql(TYPO3_db, $query);
echo mysql_error();
header ('Location: '.t3lib_div::locationHeaderUrl('index.php?id=79'));
} else {
$content='
<h3>Erstelle hier Dein Profil:</h3>
<form enctype="multipart/form-data" action="'.$this->pi_getPageLink($GLOBALS["TSFE"]->id).'" method="POST">
<input type="hidden" name="no_cache" value="1">
<input type="text" name="'.$this->prefixId.'[DATA][vname]">
<input type="text" name="'.$this->prefixId.'[DATA][nname]">
<input type="text" name="'.$this->prefixId.'[DATA][firma]"">
<input type="text" name="'.$this->prefixId.'[DATA][position]">
<input type="text" name="'.$this->prefixId.'[DATA][phone]">
<input type="text" name="'.$this->prefixId.'[DATA][mail]">
<input type="hidden" name="MAX_FILE_SIZE" value="5000">
<input type="file" name="'.$this->prefixID.'[FILE][foto]" value="40">
<input type="submit" name="'.$this->prefixId.'[submit_button]" value="SEND FORM!">
</form>
';
}
return $this->pi_wrapInBaseClass($content);
}
}
if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/matthi_member/pi1/class.tx_matthimember_pi1.php"]) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/matthi_member/pi1/class.tx_matthimember_pi1.php"]);
}
?>
I have played a lot around with the lines concerning the "photo" but not any of my variations worked ....
By the way, I dont know, if it is that good or not to store binarie files in the db, but the other way would be much more hazzle, as you further should track the name of the pic etc.....
Hi Mathias,
it works like the regular PHP fileupload, but use
$userfile = $GLOBAL["HTTP_POST_FILES"["image"]["tmp_name"];
$userfile_name = $GLOBALS["HTTP_POST_FILES"]["image"]["name"];
image is the name of your file input field!
User $userfile to adress the temporary uploaded file and
$userfile_name for the original users filename.
Bye,
Martin
In your case rename your file input field to:
<input type="file" name="image" value="40">
and insert the line
$foto = $GLOBAL["HTTP_POST_FILES"]["image"]["tmp_name"];
(there was a ] missing in my first post!)
before:
$data = addslashes(fread(fopen($foto, "r")));
and then insert everything into the db.
Martin
Hi Martin, thank you for your fast reply....
all that sound s very good for me....but still it doesnt work.
If you dont mind, can you have another look over the actual code ?
Here is the warning i get:
Warning: Wrong parameter count for fread() in ..../typo3conf/ext/matthi_member/pi1/class.tx_matthimember_pi1.php on line 52
This is line 52:
$data = addslashes(fread(fopen($foto, "r")));
Just put the debug on, this is the result:
DATA vname hermann
nname Hufnagel
firma haimhauser 3
position leitung
phone 0782-928 837
mail mile@deut.de
***
submit_button SEND FORM!
*** So, for any reason, there is no info about the file
The whole code follows up
Anyway, thank you very much
matthi
<?php
/***************************************************************
* Copyright notice.......................................................
*/
require_once(PATH_tslib."class.tslib_pibase.php");
class tx_matthimember_pi1 extends tslib_pibase {
var $prefixId = "tx_matthimember_pi1"; // Same as class name
var $scriptRelPath = "pi1/class.tx_matthimember_pi1.php"; // Path to this script relative to the extension dir.
var $extKey = "matthi_member"; // The extension key.
/**
* [Put your description here]
*/
function main($content,$conf) {
$this->conf=$conf;
$this->pi_setPiVarDefaults();
$this->pi_loadLL();
if(isset ($this->piVars['submit_button'])) {
// WHAT TO DO if content is submitted
// t3lib_div::debug($this->piVars);
$foto = $GLOBALS["HTTP_POST_FILES"]["image"]["tmp_name"];
$foto_name = $GLOBALS["HTTP_POST_FILES"]["image"]["name"];
$data = addslashes(fread(fopen($foto, "r")));
$query = 'INSERT INTO tx_matthimember_table (vname,nname,firma,position,phone,mail,foto,pid)
VALUES("'.addslashes($this->piVars['DATA']['vname']).'",
"'.addslashes($this->piVars['DATA']['nname']).'",
"'.addslashes($this->piVars['DATA']['firma']).'",
"'.addslashes($this->piVars['DATA']['position']).'",
"'.addslashes($this->piVars['DATA']['phone']).'",
"'.addslashes($this->piVars['DATA']['mail']).'",
"$data",
"'.$GLOBALS['TSFE']->id.'")';
$res = mysql(TYPO3_db, $query);
echo mysql_error();
header ('Location: '.t3lib_div::locationHeaderUrl('index.php?id=79'));
} else {
$content='
<h3>Erstelle hier Dein Profil:</h3>
<form enctype="multipart/form-data" action="'.$this->pi_getPageLink($GLOBALS["TSFE"]->id).'" method="POST">
<input type="hidden" name="no_cache" value="1">
<input type="text" name="'.$this->prefixId.'[DATA][vname]">
<input type="text" name="'.$this->prefixId.'[DATA][nname]">
<input type="text" name="'.$this->prefixId.'[DATA][firma]"">
<input type="text" name="'.$this->prefixId.'[DATA][position]">
<input type="text" name="'.$this->prefixId.'[DATA][phone]">
<input type="text" name="'.$this->prefixId.'[DATA][mail]">
<input type="hidden" name="MAX_FILE_SIZE" value="50000">
<input type="file" name="image" value="40">
<input type="submit" name="'.$this->prefixId.'[submit_button]" value="SEND FORM!">
</form>
';
}
return $this->pi_wrapInBaseClass($content);
}
}
if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/matthi_member/pi1/class.tx_matthimember_pi1.php"]) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/matthi_member/pi1/class.tx_matthimember_pi1.php"]);
}
?>
Hi Matthias,
> This is line 52:
> $data = addslashes(fread(fopen($foto, "r")));
use fread like this:
$data = addslashes(fread(fopen($foto, "r"), filesize($foto)));
This should work.
Martin
Hi Martin, Danke, super.
But unfortunatly it still doesn´t work.
Now I get a further errormessage telling me, no such function found..
Warning: filesize() [function.filesize]: Stat failed for (errno=2 - No such file or directory....
If you have done that before, I really hope we can fix that with your experience....
Maybe I just have to declare some functions in front like the file size stuff etc.... ??
I will send you a PM where you can see the "desaster" online ..lol
Thank you very much anyway
matthi