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
//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($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
 
	// 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!

$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

thank you for replying! so it’s seeing the path as a file extension? How do i fix this then?

No, that’s not happening, I assure you. :slight_smile: 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!”

ok, I’ve changed this part:

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

into same directory:

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

My real problem is with this one instead,

  $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:

$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?

try.
http://localhost/PDRM/QR_Code/image.png
As the path, after all you are in the web directory.

I’ve tried it and got error:

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

I would guess that the path is fine.
“Invalid argument”
tells me you have a coding error.