Well the problem with you solution is I have to redo whatever I do to make the image which seems inefficient.
Here's my code from a wider view:
class Bundle{
var $something, $or, $other, $image, $image_type;
//constructor
function Bundle($a){
if (is_array($a)){
foreach ($a as $k=>$v){
$this->$k = $v;
}
elsif (is_int($a)){
//get the object from database
}
}
//class method
function show(){
echo "<h1>Hi There". $this->something."</h1>";
echo "<img src="image.php?bundle=".$this->something";
}
}
///// end class
image.php
$i = $_GET['bundle']
$bundle = new Bundle($i);
header ("Content-type: "$bundle->image_type);
echo($bundle->image); The above works okay if I must to something like:
$b = new Bundle(7);
$b->show();
but I'm still stuck when I get the image from a form.
$something = $_POST['something'];
$or = $_POST['or'];
$other = $_POST['other'];
$type = $_FILES['image']['type'];
$image = fread(fopen($_FILES['image']['tmp_name'], "r"), $_FILES['image']['size'));
$a = array('something'=>$something,
'or'=>$or,
'other'=>$other,
'image'=> $image,
'image_type'=>$type);
$bundle = new Bundle($a);
$bundle->show(); won't work at all. So far as I can tell there is no way to make show work as I'd have to pass all the same info to image.php.
I suppose below could be a compromise:
class Bundle{
var $something, $or, $other, $image, $image_type;
//constructor
function Bundle($a){
if (is_array($a)){
foreach ($a as $k=>$v){
$this->$k = $v;
}
elsif (is_int($a)){
//get the object from database
}
}
//class method
function show(){
echo "<h1>Hi There". $this->something."</h1>";
if (isset($this->image_file){
echo "<img src=".$this->image_file.">";}
else
echo "<img src="image.php?bundle=".$this->something";
}
}
///// end class
////from form
$something = $_POST['something'];
$or = $_POST['or'];
$other = $_POST['other'];
$type = $_FILES['image']['type'];
$image = fread(fopen($_FILES['image']['tmp_name'], "r"), $_FILES['image']['size'));
$image_file = temp_nam();
$i = fopen($image_file, "w");
fwrite($i, $image);
$a = array('something'=>$something,
'or'=>$or,
'other'=>$other,
'image'=> $image,
'image_type'=>$type,
'image_file'=>$image_file);
$bundle = new Bundle($a);
$bundle->show();
so that a temp fil is writen if not from database.
I still say, there should be a way I can sen the raw data directly to a file.