By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,993 Members | 1,984 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,993 IT Pros & Developers. It's quick & easy.

Need help modifying this PHP script

P: n/a
I was wondering if someone here could help me with modifying this PHP
template so that it does something very specific for me. My knowledge
of PHP is very limited (I'm more of a Cold Fusion developer), which is
why I'm inquiring here.

Anyways, first I'll show you the PHP code, and then I'll explain what
kind of modification I need to have applied:

------------------------------------------------------------------------------
<?
include ("config.php");
include("imgprocess.php");

//create a php code that will be evaluated later, each time displaying
the image...

$imgdata =
"\$points=\"$points\";\$colors=\"$colors\";\$penci lwidths=\"$pencilwidths\";";

//...pack it in a compressed archive...

$newgzfile = gzopen($newid.".gz", "w9");
gzwrite($newgzfile, $imgdata);
gzclose($newgzfile);

//...and free some memory.

unset ($imgdata);

//create virtualy the image from the flash compression algorythm;

$image=makeimg();

//create physically the thumbnail from our gd virtual image.

$image2 = ImageCreate($thumbsize,$thumbsize);
imagecopyresized ( $image2 , $image , 0 , 0 , 0 , 0 , $thumbsize
,$thumbsize, 450 ,450 ) ;
if($thumbformat == "jpg"){
Imagejpeg($image2,"temp".$newid.".jpg",$thumbquali ty);
}else{
Imagepng($image2,"temp".$newid.".png");
}
//now lets tell flash every thing is ok

echo "everything=okaisayhellotoyourmama";

?>
------------------------------------------------------------------------------

This PHP file, as best as I can tell, writes a file named "temp.jpg" to
a specific directory on the server (defined in the config.php file).
What I need is to have the template modified so that it "waits" to
make sure that the file named "temp.jpg" DOES NOT EXIST at that
location before attempting to write the file. I've written some Cold
Fusion routines which promptly rename the temp.jpg files and moves them
to a different location, but since this will be used in a multi-user
environment, I have to make sure that temp.jpg never gets overwritten.
I'm not sure if this is even possible to accomplish or not, but I thank
you in advance for whatever assistance you can offer.

Cheers,
- yvan

Aug 6 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
yv**@atzilut.com wrote:
: I was wondering if someone here could help me with modifying this PHP
: template so that it does something very specific for me. My knowledge
: of PHP is very limited (I'm more of a Cold Fusion developer), which is
: why I'm inquiring here.

: Anyways, first I'll show you the PHP code, and then I'll explain what
: kind of modification I need to have applied:

: ------------------------------------------------------------------------------
: <?
: include ("config.php");
: include("imgprocess.php");

: //create a php code that will be evaluated later, each time displaying
: the image...

: $imgdata =
: "\$points=\"$points\";\$colors=\"$colors\";\$penci lwidths=\"$pencilwidths\";";

: //...pack it in a compressed archive...

: $newgzfile = gzopen($newid.".gz", "w9");
: gzwrite($newgzfile, $imgdata);
: gzclose($newgzfile);

: //...and free some memory.

: unset ($imgdata);

: //create virtualy the image from the flash compression algorythm;

: $image=makeimg();

: //create physically the thumbnail from our gd virtual image.

: $image2 = ImageCreate($thumbsize,$thumbsize);
: imagecopyresized ( $image2 , $image , 0 , 0 , 0 , 0 , $thumbsize
: ,$thumbsize, 450 ,450 ) ;
: if($thumbformat == "jpg"){
: Imagejpeg($image2,"temp".$newid.".jpg",$thumbquali ty);
: }else{
: Imagepng($image2,"temp".$newid.".png");
: }
: //now lets tell flash every thing is ok

: echo "everything=okaisayhellotoyourmama";

: ?>
: ------------------------------------------------------------------------------

: This PHP file, as best as I can tell, writes a file named "temp.jpg" to
: a specific directory on the server (defined in the config.php file).
: What I need is to have the template modified so that it "waits" to
: make sure that the file named "temp.jpg" DOES NOT EXIST at that
: location before attempting to write the file. I've written some Cold
: Fusion routines which promptly rename the temp.jpg files and moves them
: to a different location, but since this will be used in a multi-user
: environment, I have to make sure that temp.jpg never gets overwritten.
: I'm not sure if this is even possible to accomplish or not, but I thank
: you in advance for whatever assistance you can offer.

: Cheers,
: - yvan

Make the various instances of the script cooperate by using a unique name
each time for the temporary file.

The "uniqid" function may be appropriate for this task.

At the top of the code you create a string that is the unique name, then
later on the script uses that name. Each instance will have a different
name.

I can't show you exactly because the code you show does not seem to
include all the accesses to the file being created.
--

This space not for rent.
Aug 7 '05 #2

P: n/a
Thanks for your reply Malcom, but I thought I'd let you know that
someone just emailed me a modified version of the template which does
exactly what I need it to. The code he sent me is as follows:

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

if($thumbformat == "jpg"){
while (file_exists("temp".$newid.".jpg")) {
sleep(1);
}
Imagejpeg($image2,"temp".$newid.".jpg",$thumbquali ty);
}else{
while (file_exists("temp".$newid.".png")) {
sleep(1);
}
Imagepng($image2,"temp".$newid.".png");
}

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

But liek I said, -- thanks anyways. I'm always grateful for the time
folks invest in helping me trying to work out these programming
riddles. I appreciate your efforts!

Cheers,
- yvan

Aug 7 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.