php页面重定向到另一个页面

时间:2017-02-25 10:27:06

标签: php

我正在使用html画布页面进行在线绘图,我将其与save.php文件链接,该文件将画布上的绘图数据保存在我的数据库中 这是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();


}

现在图形获得了http://www.example.com/?p= $ row_id之类的链接,我尝试在将图形发布到该链接后重定向用户,我尝试了

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

但它不适合我! 除了(标题)以外的任何其他解决方案?

0 个答案:

没有答案