2

i am using html canvas page for drawing online and i am linking it with save.php file which saves the drawing data from the canvas on my database and this is the code of save.php

if (isset($GLOBALS["HTTP_RAW_POST_DATA"]))
{


  // Get the data
  $imageData=$GLOBALS['HTTP_RAW_POST_DATA'];

 //echo "ok1";
  // Remove the headers (data:,) part.
  // A real application should use them according to needs such as to check image type
  $filteredData=substr($imageData, strpos($imageData, ",")+1);

  // Need to decode before saving since the data we received is already base64 encoded
  $unencodedData=base64_decode($filteredData);

  //echo "unencodedData".$unencodedData;

  // Save file. This example uses a hard coded filename for testing,
  // but a real application can specify filename in POST variable
  $file = ''.rand().'';
  $fp = fopen( $file.'.png', 'wb' );
  fwrite( $fp, $unencodedData);
  fclose( $fp );


//echo "ok2";


  $servername = "example";
  $username = "example";
  $password = "example";
  $dbname = "example";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
//$usr = wp_get_current_user();
    //$uid = (int) $usr->ID;


//echo "ok3";
//global $current_user1;
//$current_user = wp_get_current_user();
//global $current_user;
//get_currentuserinfo();

$root = dirname(dirname(__FILE__));
if (file_exists($root.'/wp-load.php')) {
require_once($root.'/wp-load.php');
//echo "EXISTS";
} 
$user_id = get_current_user_id();
//echo "ok4";

$content1 = '<img class="alignnone  wp-image-11" src="http://example.com/wp-includes/'.$file.'.png" alt="" />';
 // $usr=get_current_user_id();
$sql = "INSERT INTO wp_njvt_posts (post_date,post_date_gmt,post_author, post_content, post_title, post_excerpt, post_password, post_name, to_ping, pinged, post_content_filtered, guid, post_mime_type)
VALUES (NOW(),NOW(),'$user_id','$content1', '', '', '','$file','','','','http://www.example.com/?p=$file','')";
$row_id = 0;
 //  $usr=0;

if ($conn->query($sql) === TRUE) {
    echo "".$file.".png";
    $row_id = $conn->insert_id;
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}
$sql2 =  "UPDATE wp_njvt_posts SET guid = 'http://www.example.com/?p=$row_id' WHERE ID = $row_id" ;





if ($conn->query($sql2) === TRUE) {
    echo "   ***your drawing was published  SUCCESSFULY!*** ";

//header("Location: http://www.example.com/?p=$row_id");


} else {
    echo "Error:". $sql2 . "<br>" . $conn->error;
}


$conn->close();


}

now the drawing gets a link like http://www.example.com/?p=$row_id and i tried redirect the user after publishing the drawing to that link and i tried it with

header("Location: http://www.example.com/?p=$row_id");

but it is not working with me! any other solutions other than (header) ?

  • is it echo ***your drawing was published SUCCESSFULY!*** ? Check your condition – Omi Feb 25 '17 at 10:30
  • The most common issue with http location headers "not working" is that they are not send because other content has been sent before. Note that headers have to be send before any other content. – arkascha Feb 25 '17 at 10:38
  • worth checking : http://stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php – niceman Feb 25 '17 at 11:01

0 Answers0