Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 18th, 2007, 3:58 PM   #11
woozy
Newbie
 
Join Date: Mar 2007
Posts: 15
Rep Power: 0 woozy is on a distinguished road
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.
woozy is offline   Reply With Quote
Old Mar 18th, 2007, 9:44 PM   #12
Styx
Programmer
 
Join Date: Mar 2007
Posts: 39
Rep Power: 0 Styx is on a distinguished road
I don't believe there is a way. The image needs its own header information.

Your uploads, do you store them in the database? If so, could you just get them from there?
Styx is offline   Reply With Quote
Old Mar 18th, 2007, 10:23 PM   #13
woozy
Newbie
 
Join Date: Mar 2007
Posts: 15
Rep Power: 0 woozy is on a distinguished road
Quote:
Originally Posted by Styx View Post
I don't believe there is a way. The image needs its own header information.

Your uploads, do you store them in the database? If so, could you just get them from there?
Well...... yes.


There's two stages.
1) Creating them from a form and checking and proofing them before comitting them to the database.
For this stage I can make and refer to temp files.
2) once committed to DB I can use call the image from the database.
A neat tidyness is that I can call "unlink" on the temp files at precisely the same time as committing them to the database.

It's a fix. It'll work.

I don't really like it, though. Seems redundant. But it definately will work.
woozy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
GOTO Sys. Tray Src. (code Snippet) Cipher Show Off Your Open Source Projects 1 Oct 17th, 2006 1:38 PM
Jackpot game zorin Visual Basic 3 Jun 10th, 2005 1:19 PM
Help in QBASIC (I think it's similar to VB) phoenix987 Visual Basic 3 May 9th, 2005 12:33 PM
Help with a QBASIC program phoenix987 Other Programming Languages 4 May 5th, 2005 12:27 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:10 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC