SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Nov 2013
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    image did not save on database

    Hi, I was trying to save a qr code into a directory path (../QR_Code/image.png) which will later will be saved on my database.

    PHP Code:
     <?php
    //if ($_POST['submit']) { 
    if ($_SESSION['MM_Username']) {


        
    //$msg = $_REQUEST['msg'];
    $msg$row_RSU['QR_CODES'];
        
    $url  'http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl='.$msg;
     
        
    // initialize cURL settings
        
    $ch curl_init ($url);
        
    curl_setopt($chCURLOPT_HEADER0);
        
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
        
    curl_setopt($chCURLOPT_BINARYTRANSFER,1);
        
    curl_setopt($chCURLOPT_FOLLOWLOCATIONtrue);
     
        
    // fetch raw data
        
    $rawdata curl_exec($ch);
        
    curl_close($ch);
         
        
    // convert it to a GD image and save
        
    $img imagecreatefromstring($rawdata);

    // declare image path

    $image_path='c:\domains\mywebsite.com\wwwroot\PDRM\QR_Code\image.png';

        
    // now save a copy of the new image to the cache directory
        
    imagePNG($img$image_path);

        print 
    '<center><img src=http://mywebsite.com/PDRM/image.png><br>';

        
        
    //print('<font color=#30afd8><H2>Saved QR Code.</H2></font>');

        
    imagedestroy($img);
    }   
    ?>
    But when I check at my database the value is still null. I'm not very familiar with window server. Before this when I was working on Apache server, the image path i used was /var/www and it saved the image perfectly on the database. Maybe the image path is incorrect? Any thoughts would be helpful. Thanks!

  2. #2
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,035
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $image_path='c:\domains\mywebsite.com\wwwroot\PDRM\QR_Code\image.png'
    Windows might be interpreting anything after the .com to be a file extension so maybe it's seeing it as a file called mywebsite with everything that follows that bit as a file extension
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  3. #3
    SitePoint Member
    Join Date
    Nov 2013
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you for replying! so it's seeing the path as a file extension? How do i fix this then?

  4. #4
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, that's not happening, I assure you. I don't get why you posted image saving code, but are asking why something in your database is null...

    Anyway, for paths, I see you have:

    ...wwwroot\PDRM\QR_Code\image.png

    vs

    http://mywebsite.com/PDRM/image.png

    Which probably aren't the same path, so your image wouldn't show up, for another thing. Unless the missing image is what you mean by "null database!"
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  5. #5
    SitePoint Member
    Join Date
    Nov 2013
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, I've changed this part:
    PHP Code:
    //print '<center><img src=http://mywebsite.com/PDRM/image.png><br>'; 
    into same directory:
    PHP Code:
    print '<center><img src=http://mywebsite.com/PDRM/QR_Code/image.png><br>'
    My real problem is with this one instead,

    PHP Code:
      $img imagecreatefromstring($rawdata);

    // declare image path

    $image_path='c:\domains\mywebsite.com\wwwroot\PDRM\QR_Code\image.png';

        
    // now save a copy of the new image to the cache directory
        
    imagePNG($img$image_path); 
    I want it to save the image inside QR_Code directory and write into my database with field named 'imagePNG'. But nothing happened. And the imagePNG still contain NULL value.

    Previously, I've been using the same codes on linux with this image path:

    PHP Code:
    $image_path='/var/www/mywebsite/html/PDRM/QR_Code/image.png' 
    The image.png was written at both QR Code directory and into imagePNG field. So i'm thinking this must be a wrong way/wrong directory to write the image( c:\domains\mywebsite.com\wwwroot\PDRM\QR_Code\image.png'; ). Or is it not?

  6. #6
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,101
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    try.
    http://localhost/PDRM/QR_Code/image.png
    As the path, after all you are in the web directory.
    What I lack in acuracy I make up for in misteaks

  7. #7
    SitePoint Member
    Join Date
    Nov 2013
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've tried it and got error:

    Code:
    Warning: imagepng() [function.imagepng]: Unable to open 'http://localhost/PDRM/QR_Code/image.png' for writing: Invalid argument in C:\Domains\datacalibre.com\wwwroot\PDRM\updated5.php on line 1088

  8. #8
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,101
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I would guess that the path is fine.
    "Invalid argument"
    tells me you have a coding error.
    What I lack in acuracy I make up for in misteaks


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •