473,403 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

i tried atli's manual and the picture is not appearing?

Paul NIcolai Sunga
here's the code for retrieving the info in the pic..but the info in filedata only showing a set of strings..

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php 
  3. $Link = mysqli_connect("localhost","root","tupi", "amyak_maleh");
  4.     if(mysqli_connect_errno()){
  5.         die("Mysql connection failed:".mysqli_connect_errno());
  6.         }
  7. //$result1 = mysqli_query($Link, "SELECT filedata FROM filestorage ORDER BY form_no DESC LIMIT 1");
  8. $result1 = mysqli_query($Link, "SELECT fileid, filename, filemime, filesize, created, filedata from filestorage");
  9. if($result1)
  10. {
  11. if(mysqli_num_rows($result1) == 0){
  12. echo "<p> there are no files in the database</p>";
  13. }
  14. else
  15. {
  16. echo "<table width = '100%'><tr>";
  17. echo "<td><b>Name</b></td>";
  18. echo "<td><b>Mime</b></td>";
  19. echo "<td><b>Size(bytes)</b></td>";
  20. echo "<td><b>Created</b></td>";
  21. echo "<td><b>Filedata</b></td>";
  22.  
  23. while($row = mysqli_fetch_array($result1))
  24. {
  25. echo "<tr><td>".$row['filename']."</b></td>";
  26. echo "<td>".$row['filemime']."</b></td>";
  27. echo "<td>".$row['filesize']."</b></td>";
  28. echo "<td>".$row['created']."</b></td>";
  29. echo "<td><input type=\"image\" src=".$row['filedata']."/></b></td></tr>";
  30. }
  31.  
  32. echo "</table>";
  33. }
  34. mysqli_free_result($result1);
  35. }
  36. else
  37. {
  38. echo "error! sql query failed";
  39. echo "<pre>".$link->error."</pre>";
  40. }
  41. mysqli_close($Link);
  42.  
  43.  
  44. ?>
  45.  
Jul 30 '09 #1
34 3114
Dormilich
8,658 Expert Mod 8TB
as for any image in html, the src attribute specifies an URI to the image, not the image data itself.
Jul 30 '09 #2
how could i convert the strings into an image? what function should i use? to convert it?



thanks
Jul 30 '09 #3
Dormilich
8,658 Expert Mod 8TB
you're not getting the point here. the image data belong into a separate file.

Expand|Select|Wrap|Line Numbers
  1. // html
  2. <input type="image" src="path/to/image.php"/>
Expand|Select|Wrap|Line Numbers
  1. // image.php
  2. // ...
  3. echo $row['filedata'];
if you closely examine Atli's code samples, you'll notice that he doesn't mix (binary) image data with html code.
Jul 30 '09 #4
i see.. it should be in a different page? ..so that it will be a valid code in src?
Jul 30 '09 #5
Dormilich
8,658 Expert Mod 8TB
@Paul NIcolai Sunga
the URI of that page
Jul 30 '09 #6
Canabeez
126 100+
Here, save this as image.php
Expand|Select|Wrap|Line Numbers
  1. header("Content-Type: image/jpeg");
  2.  
  3. $fileid = isset($_REQUEST['fileid']) ? $_REQUEST['fileid'] : false;
  4.  
  5. if($fileid)
  6. {
  7.    $Link = mysqli_connect("localhost","root","tupi", "amyak_maleh");
  8.    if(mysqli_connect_errno())
  9.    {
  10.       die("Mysql connection failed:".mysqli_connect_errno());
  11.    }
  12.  
  13.    $result = mysqli_query($Link, "SELECT filedata from filestorage where fileid={$fileid}");
  14.  
  15.    if(is_resource($result))
  16.    {
  17.       $row = mysql_fetch_row($result);
  18.       echo $row['filedata'];
  19.    }
  20. }
Then call:
Expand|Select|Wrap|Line Numbers
  1. <input type="image" src="image.php?fileid=YOUR_FILE_ID">
Jul 30 '09 #7
the result is

Submit Query

why is that?


thanks
Jul 31 '09 #8
here's the code, and it appears only a this string: Submit Query


Expand|Select|Wrap|Line Numbers
  1. <input type="image" src="image.php?fileid=<?Php $form_no; ?>" />
  2.  


thanks
Jul 31 '09 #9
any other suggestions please?


thanks
Jul 31 '09 #10
Dormilich
8,658 Expert Mod 8TB
where does "Submit Query" come from?
Jul 31 '09 #11
from the image.php.



thanks
Aug 3 '09 #12
whats this?when i click the submit query which is the one appeared insted of the image, it jumps to the image.php page then this is what appears:

http://localhost/image.php?x=&y=
Aug 3 '09 #13
Dormilich
8,658 Expert Mod 8TB
@Dormilich
I mean, where dou you define such a string (which line of code causes that to appear)?
Aug 3 '09 #14
this is the code..

Expand|Select|Wrap|Line Numbers
  1. <form action="image.php" method="post">
  2.  
  3. <input type="image" src="image.php?form_no=<?Php echo $form_no; ?>" /> 
  4.       </form>
Aug 3 '09 #15
Dormilich
8,658 Expert Mod 8TB
well, it does not explain where the string comes from, but it explains the strange submit.

obviously image.php is designed to be an image (representation), thus if you put it in your form's action it will be executed onsubmit (say, if you submit the form, you'll be returned an image (which is possible, but doesn't make sense)). solution: put the form handling script in the action attribute.
Aug 3 '09 #16
solution: put the form handling script in the action attribute.

what exactly i will put in the action attribute?
Aug 3 '09 #17
Dormilich
8,658 Expert Mod 8TB
@Paul NIcolai Sunga
.....................


the script (resp. its file name) that processes the form data (may be the same as the current page)
Aug 3 '09 #18
what shall i do? it is still not working..
Aug 7 '09 #19
Dormilich
8,658 Expert Mod 8TB
what is not working, the form or the image?
Aug 7 '09 #20
the image is not showing.. i tried to show it through the src itself and its okei but when the image that came from the database it is not showing,.. maybe the problem is in the database or in the code, but there is no sign error in the codes.
Aug 10 '09 #21
Dormilich
8,658 Expert Mod 8TB
ok, then you have to make sure that the picture is saved correctly in the DB . there are some MySQL GUIs out, but unless you have a Mac I can’t recommend anything.

(If that’s possible I could try connecting to your DB and look myself)
Aug 10 '09 #22
Canabeez
126 100+
Here's one I use... SQLYog
Aug 10 '09 #23
Dormilich
8,658 Expert Mod 8TB
@Canabeez
does it show you any pictures?
Aug 10 '09 #24
i tried another code:
here's the code. it only displays a blank photo. i mean an x that is usually seen in a blank photo..
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $Link = mysqli_connect("localhost","root","tupi", "amyak_maleh");
  4.             if (!$Link)
  5.               {
  6.               trigger_error("Could not connect", E_USER_ERROR );
  7.               }
  8.  
  9. $result=mysqli_query($Link, "SELECT * FROM pix");
  10. while($row=mysqli_fetch_assoc($result))
  11. {
  12.  header("Content-type: image/jpeg");
  13.   echo "<img src=\"".$row['imgdata']."\" alt=\"".$row['title']."\" width=\"100\" length=\"100\"/>";
  14. }
  15. ?>
  16.  
Aug 12 '09 #25
Dormilich
8,658 Expert Mod 8TB
@Paul NIcolai Sunga
this is completely wrong, the src attribute has to be an url!
Aug 12 '09 #26
Dormilich
8,658 Expert Mod 8TB
I’ll give you a working example

HTML
Expand|Select|Wrap|Line Numbers
  1.     <h4>
  2.         <a class="hook" id="mord">Mord an Bord</a>
  3.     </h4>
  4.  
  5.     <p>11. Januar 2009, SachsenSonntag</p>
  6.     <div class="mitte">
  7.         <img src="img.php?iid=sas091" width="150" height="99" alt="Bild des Zeitungsartikels" title="Wohl bekomm’s! Ein Schlückchen zur Begrüßung der Passagiere" id="img_sas091"/>
  8.     </div>
img.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     require 'load.img.php';
  3.     $img = new ArticleIMG;
  4.     $img->display();
  5. ?>
methods
Expand|Select|Wrap|Line Numbers
  1.     public function display()
  2.     {
  3.         if (!$this->requestImage())
  4.         {
  5.             exit;
  6.         }
  7.  
  8.         if (!empty($this->DBimg['img_mime']) and !empty($this->DBimg['img_size']) and !empty($this->DBimg['img_data']))
  9.         {
  10.             header('Content-Type: ' . $this->DBimg['img_mime']);
  11.             header('Content-Length: ' . $this->DBimg['img_size']);
  12.             echo $this->DBimg['img_data'];
  13.         }
  14.     }
  15.  
  16.     protected function requestImage()
  17.     {
  18.         $this->load();
  19.  
  20.         if ($this->checkID($this->IID))
  21.         {
  22.             return $this->getImageData();
  23.         }
  24.         return false;
  25.     }
  26.  
  27.     private function getImageData()
  28.     {
  29.         try 
  30.         {             
  31.             $PS = aDB::execute('img', array(':id' => $this->IID));
  32.             $this->DBimg = $PS->fetch(PDO::FETCH_ASSOC);
  33.         }
  34.         catch (PDOException $pdo)
  35.         {
  36.             ErrorLog::logException($pdo, __CLASS__, __METHOD__);
  37.             return false;
  38.         }
  39.         return true;
  40.     }
Aug 12 '09 #27
is this correct?
Expand|Select|Wrap|Line Numbers
  1.  
  2. $pic = $_FILES['Browse'];
  3.  
  4. $formid = mysqli_query($Link, "Select form_no from registration_form where last_insert_id() = form_no");
  5.  
  6. $formnum = mysqli_fetch_row($formid);
  7.  
  8.  
  9. $querypic = mysqli_query($Link, "INSERT INTO pix(pid, imgdata) values('$formnum', '$pic')");    
  10.  
  11.  
  12.  
i am not certain with this code..
Aug 12 '09 #28
Dormilich
8,658 Expert Mod 8TB
@Paul NIcolai Sunga
completely unnecessary (have a close look at what you want to do here… ;))

otherwise I can’t tell (too less info)
Aug 12 '09 #29
okei.. im trying a lot of codes that is why i am so confused.. the issue about the displaying picture from mysql is still unsolved..
Aug 12 '09 #30
Dormilich
8,658 Expert Mod 8TB
@Paul NIcolai Sunga
so, did you verify that the picture is in the DB (and not corrupted)?
Aug 12 '09 #31
yeah.. in atli's code there were files in the DB but when i tried to check my own, there was no files.. im going to start again.. hope i can do it.. i'll try to fix the codes.. the insert query maybe has an error..
here's now my code:
Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php 
  3. error_reporting (E_ALL ^ E_NOTICE);
  4.  
  5. $pid = base64_decode($_GET['id']);
  6.  
  7. if(isset($_FILES['uploaded_file']))
  8. {
  9. if($_FILES['uploaded_file']['error'] == 0)
  10.     {$Link = mysqli_connect("localhost","root","tupi", "amyak_maleh");
  11.     if(mysqli_connect_errno()){
  12.         die("Mysql connection failed:".mysqli_connect_errno());
  13.         }
  14.         $name = mysqli_real_escape_string($Link, $_FILES['uploaded_file']['name']);
  15.         $data = mysqli_real_escape_string($Link, file_get_contents($_FILES ['uploaded_file']['tmp_name']));
  16.  
  17.         $query = "INSERT INTO pix(pid, title, imgdata) values('$pid', '$name', '$data')";
  18.  
  19.         $result = mysqli_query($Link, $query);
  20.         if($result)
  21.         {
  22. $asd = "Succes! YOur file was successfully added!";
  23. $alert = base64_encode($asd);
  24. header("Location:registration.php?alert=$alert");
  25. exit();
  26.         }
  27.         else
  28.         {
  29.         $asd = "Error! An error occurred while the file was being uploaded.
  30.         Error code:".$_FILES['uploaded_file']['error'];
  31. $alert = base64_encode($asd);
  32. header("Location:picul.php?alert=$alert");
  33. exit();
  34.         }
  35.         mysqli_close($Link);
  36. }
  37.  
  38.  
it is not inserting..
Aug 12 '09 #32
@Paul NIcolai Sunga
with this code the data has inserted.. but now im having a problem retrieving the photo..
Aug 13 '09 #33
i used this:
Expand|Select|Wrap|Line Numbers
  1. <input name="image" type="image" src="asdf.php?imgid=<?Php echo $form_no; ?>" width="110" height="100"/>
  2.  
asdf.php where the image come from.
Expand|Select|Wrap|Line Numbers
  1. error_reporting (E_ALL ^ E_NOTICE);
  2.  
  3. $id = $_GET['imgid'];
  4.  
  5. $Link = mysqli_connect("localhost","root","***", "***");
  6.             if (!$Link)
  7.               {
  8.               trigger_error("Could not connect", E_USER_ERROR );
  9.               }
  10. if(!isset($id) || empty($id)){
  11. die("Please select your image!");
  12. }else{
  13.  
  14. $query = mysqli_query($Link, "SELECT * FROM pix WHERE pid='$id' ");
  15. $row = mysqli_fetch_assoc($query);
  16. $content = $row['imgdata'];
  17.  
  18. header('Content-type: image/jpg');
  19. echo $content;
  20.  
  21. }
  22.  
and i tried this one: it still not showing:
Expand|Select|Wrap|Line Numbers
  1.   header('Content-Type: image/jpeg');
  2.     $id = $_GET['imgid'];
  3.    $id = isset($_REQUEST['imgid']) ? $_REQUEST['imgid'] : false;
  4.  
  5.    if($id)
  6.     {
  7.       $Link = mysqli_connect("localhost","root","***", "***");
  8.       if(mysqli_connect_errno())
  9.       {
  10.          die("Mysql connection failed:".mysqli_connect_errno());
  11.     }
  12.  
  13.      $result = mysqli_query($Link, "SELECT imgdata from pix where pid = '$id' ");
  14.  
  15.       if(is_resource($result))
  16.       {
  17.          $row = mysql_fetch_row($result);
  18.           header('Content-Type: image/jpeg');
  19.         echo $row['imgdata'];
  20.  
  21.       }
  22.   }
  23.  
  24.  
the photo is not showing..which do you think the good code should i use and enhance? so that i will not get confused...


thanks a lot...
Aug 13 '09 #34
help. which code should i use?
Aug 14 '09 #35

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: larrybud2002 | last post by:
I suspect many developers here have had to write a technical manual for their software, and I'm wondering if you have any info as to industry standards for formatting. For example, should a...
14
by: Craig O'Shannessy | last post by:
Hi all, Just thought I'd mention that I really think this problem needs to be fixed. I I'm patching the 7.4RC1 JDBC drivers as we speak due to this optimiser bug, and it's the third time...
3
by: nsh | last post by:
mailing.database.mysql, comp.lang.php subject: does "LOAD DATA" EVER work?!? I've tried EVERYTHING! version info: my isp is running my web page on a linux box with php ver. 4.4.1 according to...
53
by: angelicdevil | last post by:
ok i have a folder made on the server and uploaded image files to it...the link to the image file or rather the path to the image is uploaded in the database in 'image_path' , now i want that the...
3
Paul NIcolai Sunga
by: Paul NIcolai Sunga | last post by:
are these codes are right? these are what i use in retrieving the picture.. <?Php error_reporting (E_ALL ^ E_NOTICE); $Link = mysqli_connect("localhost","root","tupi",...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.