Sign in to follow this  
babuu

Problem With Redirect Php Site From Our Site(While Download Images)

Recommended Posts

Hi,

 

we have done exporting images from php code(sample app configured in wamp server for saving image in local path) by using pure javascript (without flash).

 

we have problem with redirect php site while downloading images.Need to be page itself. Dont go php site.

 

How to solve this redirect problem?

 

 

Please check it once below php code for saving image in local path.

 

 

<?php

/**

* This file is part of the exporting module for Highcharts JS.

* www.highcharts.com/license

*

*

* Available POST variables:

*

* filename string The desired filename without extension

* tempName string The name of the file that get stored in the server temporary location

* type string The MIME type for export.

* width int The pixel width of the exported raster image. The height is calculated.

* svg string The SVG source code to convert.

*/

 

 

// Options

define ('BATIK_PATH', 'batik-rasterizer.jar');

 

///////////////////////////////////////////////////////////////////////////////

ini_set('magic_quotes_gpc', 'off');

 

$type = $_POST['type'];

$svg = (string) $_POST['svg'];

$filename = (string) $_POST['filename'];

 

// prepare variables

if (!$filename) $filename = 'chart';

if (get_magic_quotes_gpc()) {

$svg = stripslashes($svg);

}

 

 

 

$tempName = md5(rand());

 

// allow no other than predefined types

if ($type == 'image/png') {

$typeString = '-m image/png';

$ext = 'png';

 

} elseif ($type == 'image/jpeg') {

$typeString = '-m image/jpeg';

$ext = 'jpg';

 

} elseif ($type == 'application/pdf') {

$typeString = '-m application/pdf';

$ext = 'pdf';

 

} elseif ($type == 'image/svg+xml') {

$ext = 'svg';

}

$outfile = "babu/$tempName.$ext";

 

if (isset($typeString)) {

 

// size

if ($_POST['width']) {

$width = (int)$_POST['width'];

if ($width) $width = "-w $width";

}

 

// generate the temporary file

if (!file_put_contents("babu/$tempName.svg", $svg)) {

die("Couldn't create temporary file. Check that the directory permissions for

the /temp directory are set to 777.");

}

 

// do the conversion

$output = shell_exec("java -jar ". BATIK_PATH ." $typeString -d $outfile $width babu/$tempName.svg");

 

// catch error

if (!is_file($outfile) || filesize($outfile) < 10) {

echo "<pre>$output</pre>";

echo "Error while converting SVG for menlo.....";

}

 

// stream it

else {

//header("Content-Disposition: attachment; filename=$filename.$ext");

//header("Content-Type: $type");

//echo file_get_contents($outfile);

//echo $_SERVER['SERVER_NAME'];

//echo $_SERVER['REQUEST_URI'];exit;

file_put_contents("D:/sample/$tempName.$ext", file_get_contents($outfile));

 

 

}

 

// delete it

unlink("babu/$tempName.svg");

unlink($outfile);

 

 

// SVG can be streamed directly back

} else if ($ext == 'svg') {

//header("Content-Disposition: attachment; filename=$filename.$ext");

//header("Content-Type: $type");

//echo $svg;

file_put_contents("D:/sample/$tempName.$ext", $svg);

 

 

} else {

echo "Invalid type";

}

?>

--------------------------------------------------------------------------------------------------

xml file

--------

 

<chart caption='Monthly Revenue' xAxisName='Month' yAxisName='Revenue'

numberPrefix=' showValues='0' exportAtClient="0"

html5ExportHandler="http://localhost:8088/export/charts/index.php"

exportEnabled='1' exportAction='save' exportShowMenuItem='1' exportCallback="FC_Exported">

<set label='Jan' value='420000' />

<set label='Feb' value='910000' />

<set label='Mar' value='720000' />

<set label='Apr' value='550000' />

<set label='May' value='810000' />

<set label='Jun' value='510000' />

<set label='Jul' value='680000' />

</chart>

 

 

chart render code

-----------------

FusionCharts.setCurrentRenderer('JavaScript');

var myChart = new FusionCharts( "charts/Column2D.swf", "myChartId", "300", "300", "0", "1" );

myChart.setDataURL("charts/Data.xml");

myChart.render("chartContainer");

 

 

 

Click download button

----------------

 

var chartObject1 = getChartFromId('myChartId');

if( chartObject1.hasRendered() ) {

chartObject1.exportChart();

}

 

 

 

Thanks

Babu

Share this post


Link to post
Share on other sites

Please help on this

Hi,

 

we have done exporting images from php code(sample app configured in wamp server for saving image in local path) by using pure javascript (without flash).

 

we have problem with redirect php site while downloading images.Need to be page itself. Dont go php site.

 

How to solve this redirect problem?

 

 

Please check it once below php code for saving image in local path.

 

 

<?php

/**

* This file is part of the exporting module for Highcharts JS.

* www.highcharts.com/license

*

*

* Available POST variables:

*

* filename string The desired filename without extension

* tempName string The name of the file that get stored in the server temporary location

* type string The MIME type for export.

* width int The pixel width of the exported raster image. The height is calculated.

* svg string The SVG source code to convert.

*/

 

 

// Options

define ('BATIK_PATH', 'batik-rasterizer.jar');

 

///////////////////////////////////////////////////////////////////////////////

ini_set('magic_quotes_gpc', 'off');

 

$type = $_POST['type'];

$svg = (string) $_POST['svg'];

$filename = (string) $_POST['filename'];

 

// prepare variables

if (!$filename) $filename = 'chart';

if (get_magic_quotes_gpc()) {

$svg = stripslashes($svg);

}

 

 

 

$tempName = md5(rand());

 

// allow no other than predefined types

if ($type == 'image/png') {

$typeString = '-m image/png';

$ext = 'png';

 

} elseif ($type == 'image/jpeg') {

$typeString = '-m image/jpeg';

$ext = 'jpg';

 

} elseif ($type == 'application/pdf') {

$typeString = '-m application/pdf';

$ext = 'pdf';

 

} elseif ($type == 'image/svg+xml') {

$ext = 'svg';

}

$outfile = "babu/$tempName.$ext";

 

if (isset($typeString)) {

 

// size

if ($_POST['width']) {

$width = (int)$_POST['width'];

if ($width) $width = "-w $width";

}

 

// generate the temporary file

if (!file_put_contents("babu/$tempName.svg", $svg)) {

die("Couldn't create temporary file. Check that the directory permissions for

the /temp directory are set to 777.");

}

 

// do the conversion

$output = shell_exec("java -jar ". BATIK_PATH ." $typeString -d $outfile $width babu/$tempName.svg");

 

// catch error

if (!is_file($outfile) || filesize($outfile) < 10) {

echo "<pre>$output</pre>";

echo "Error while converting SVG for menlo.....";

}

 

// stream it

else {

//header("Content-Disposition: attachment; filename=$filename.$ext");

//header("Content-Type: $type");

//echo file_get_contents($outfile);

//echo $_SERVER['SERVER_NAME'];

//echo $_SERVER['REQUEST_URI'];exit;

file_put_contents("D:/sample/$tempName.$ext", file_get_contents($outfile));

 

 

}

 

// delete it

unlink("babu/$tempName.svg");

unlink($outfile);

 

 

// SVG can be streamed directly back

} else if ($ext == 'svg') {

//header("Content-Disposition: attachment; filename=$filename.$ext");

//header("Content-Type: $type");

//echo $svg;

file_put_contents("D:/sample/$tempName.$ext", $svg);

 

 

} else {

echo "Invalid type";

}

?>

--------------------------------------------------------------------------------------------------

xml file

--------

 

<chart caption='Monthly Revenue' xAxisName='Month' yAxisName='Revenue'

numberPrefix=' showValues='0' exportAtClient="0"

html5ExportHandler="http://localhost:8088/export/charts/index.php"

exportEnabled='1' exportAction='save' exportShowMenuItem='1' exportCallback="FC_Exported">

<set label='Jan' value='420000' />

<set label='Feb' value='910000' />

<set label='Mar' value='720000' />

<set label='Apr' value='550000' />

<set label='May' value='810000' />

<set label='Jun' value='510000' />

<set label='Jul' value='680000' />

</chart>

 

 

chart render code

-----------------

FusionCharts.setCurrentRenderer('JavaScript');

var myChart = new FusionCharts( "charts/Column2D.swf", "myChartId", "300", "300", "0", "1" );

myChart.setDataURL("charts/Data.xml");

myChart.render("chartContainer");

 

 

 

Click download button

----------------

 

var chartObject1 = getChartFromId('myChartId');

if( chartObject1.hasRendered() ) {

chartObject1.exportChart();

}

 

 

 

Thanks

Babu

Share this post


Link to post
Share on other sites
Guest Sashibhusan

Hi,

 

With regard to your query, please add the current page URL as a raw HTTP header using PHP function "header();".

 

Ref. Code snippet of index.php:

// delete it
unlink("babu/$tempName.svg");
unlink($outfile);

header("Location: http://www.currentPage.php"); //Set your current page URL here 

// SVG can be streamed directly back
} else if ($ext == 'svg') {
//header("Content-Disposition: attachment; filename=$filename.$ext");
//header("Content-Type: $type");
//echo $svg;
file_put_contents("D:/sample/$tempName.$ext", $svg);


} else {
echo "Invalid type";
}
?>

 

Hope this helps!

Edited by Sashibhusan

Share this post


Link to post
Share on other sites

Thank you very much for replay.

 

I am implemented header but refreshed page because java application through call php site (export images), here urls dynamically changing.

 

Please advice..

 

Hi,

 

With regard to your query, please add the current page URL as a raw HTTP header using PHP function "header();".

 

Ref. Code snippet of index.php:

// delete it
unlink("babu/$tempName.svg");
unlink($outfile);

header("Location: http://www.currentPage.php"); //Set your current page URL here 

// SVG can be streamed directly back
} else if ($ext == 'svg') {
//header("Content-Disposition: attachment; filename=$filename.$ext");
//header("Content-Type: $type");
//echo $svg;
file_put_contents("D:/sample/$tempName.$ext", $svg);


} else {
echo "Invalid type";
}
?>

 

Hope this helps!

Share this post


Link to post
Share on other sites

Page not refreshed while click download button.

 

Please advice.

Thank you very much for replay.

 

I am implemented header but refreshed page because java application through call php site (export images), here urls dynamically changing.

 

Please advice..

 

 

Share this post


Link to post
Share on other sites

Hi,

 

Page not refreshed while click download button.

 

 

Please help me.

 

Page not refreshed while click download button.

 

Please advice.

 

Share this post


Link to post
Share on other sites
Guest Sashibhusan

Hi,

 

The "header()" is redirecting me to the the previous chart page and the refresh functionality is working fine while click download button, from our end.

 

Could you please elaborate a bit more on your requirement and explain a bit on "I am implemented header but refreshed page because java application through call php site (export images), here urls dynamically changing." ?

 

Awaiting your response.

Edited by Sashibhusan

Share this post


Link to post
Share on other sites

Thanks for reply.

 

I have used header() in php but page refreshed while click download button.

 

when click download button,we are able saving images in local path but struct at php site.

 

Please find attachment for reference.

 

Thanks

Babu

 

 

 

 

 

 

Hi,

 

The "header()" is redirecting me to the the previous chart page and the refresh functionality is working fine while click download button, from our end.

 

Could you please elaborate a bit more on your requirement and explain a bit on "I am implemented header but refreshed page because java application through call php site (export images), here urls dynamically changing." ?

 

Awaiting your response.

post-28547-0-08947600-1344694758_thumb.png

Share this post


Link to post
Share on other sites
Guest Sashibhusan

Hi,

 

Could you confirm, how you are providing the URL to the "header()" function in your "index.php" page?

 

Please note that you need to provide HTTP mapping relative URL of your redirected page in index.php page.

 

Ref. Code:

header("Location: http://localhost:8088/export/sample.html"); //Assuming your main page (sample.html) is inside "export" folder of your application

 

Awaiting your feedback.

Share this post


Link to post
Share on other sites

header("Location: http://localhost/app/employe_profile.jsp"); //This is local url

Hi,

 

Could you confirm, how you are providing the URL to the "header()" function in your "index.php" page?

 

Please note that you need to provide HTTP mapping relative URL of your redirected page in index.php page.

 

Ref. Code:

header("Location: http://localhost:8088/export/sample.html"); //Assuming your main page (sample.html) is inside "export" folder of your application

 

Awaiting your feedback.

Share this post


Link to post
Share on other sites
Guest Sashibhusan

Hey,

 

Form the attached screenshot of your previous reply, it seems that your server is running on port: 8088 and you are not providing this port number in your local URL.

 

Could you please confirm once, if "employe_profile.jsp" page is accessible using the URL http://localhost/app/employe_profile.jsp in the browser ?

 

Awaiting your response!

Share this post


Link to post
Share on other sites

Thank you very much for response.

 

port:8088 worked on php site for "http://localhost:8088/export/charts/index.php" ,This url used in xml for exporting images.

 

java application Url..

http://localhost/app...oye_profile.jsp.

 

thanks

babu

 

Hey,

 

Form the attached screenshot of your previous reply, it seems that your server is running on port: 8088 and you are not providing this port number in your local URL.

 

Could you please confirm once, if "employe_profile.jsp" page is accessible using the URL http://localhost/app...oye_profile.jsp in the browser ?

 

Awaiting your response!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this