save file problem

Links for php scripts

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Tue Oct 18, 2011 3:53 pm

save file problem

Postby traviss » Tue Oct 18, 2011 4:18 pm

I have a script that saves a canvas to a png file, but when it saves it saves the file as $acc2.canvas.png and not the posted value of $acc2

here is the code.

hopefully someone can tell me what i did wrong.

Code: Select all


       // Get the data
       // 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
       //echo "unencodedData".$unencodedData;
       // Save file.  This example uses a hard coded filename for testing,
       // but a real application can specify filename in POST variable
       $fp = fopen( "signature_IMG/\\\$acc2.canvas.png", 'wb');
       fwrite( $fp, $unencodedData);
       fclose( $fp );

New php-forum User
New php-forum User
Posts: 139
Joined: Mon Nov 15, 2010 12:11 am

Re: save file problem

Postby lokanath7 » Wed Oct 19, 2011 2:29 am

the problem is in this line
$fp = fopen( "signature_IMG/\\\$acc2.canvas.png", 'wb');

u hv given 3 backward slash (\). these are used to escape character.
if u want to escape for one backward slash then give \\ or if u want two \\ then give \\\\
then it will solve ur problem. here in ur code the 3rd \ is escaping the $ symbol and treating "acc2" as normal character.

Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 2 guests