The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

Warning: fwrite(), fseek():, curl_setopt(), fclose() message w/Edit Contact php script

Highlighted
Participant

Warning: fwrite(), fseek():, curl_setopt(), fclose() message w/Edit Contact php script

Hi,


I'm getting the following errors when I update a contact using the sample Edit Contact script:


Warning: fwrite(): supplied argument is not a valid stream resource in /usr/home/jmcser/www/htdocs/x_php_sample_a_update_only/cc_class.php on line 112

Warning: fseek(): supplied argument is not a valid stream resource in /usr/home/jmcser/www/htdocs/x_php_sample_a_update_only/cc_class.php on line 113

Warning: curl_setopt(): supplied argument is not a valid File-Handle resource in /usr/home/jmcser/www/htdocs/x_php_sample_a_update_only/cc_class.php on line 114

Warning: fclose(): supplied argument is not a valid stream resource in /usr/home/jmcser/www/htdocs/x_php_sample_a_update_only/cc_class.php on line 117


Here is the referenced code cc_class:


            switch ($type) {

                case 'POST':                 

                    curl_setopt($ch, CURLOPT_POST, 1);

                    curl_setopt($ch, CURLOPT_POSTFIELDS, $parameter);

                    break;

                case 'PUT':

                    $tmpfile = tmpfile();

                    fwrite($tmpfile, $parameter);

                    fseek($tmpfile, 0);

                    curl_setopt($ch, CURLOPT_INFILE, $tmpfile);

                    curl_setopt($ch, CURLOPT_PUT, 1);

                    curl_setopt($ch, CURLOPT_INFILESIZE, strlen($parameter));

                    fclose($tmpfile);

                    break;


Does anyone have any ideas what could be causing this and a possible solution?


TIA - Tom

8 REPLIES 8
Highlighted
Participant

Warning: fwrite(), fseek():, curl_setopt(), fclose() message w/E

Hi All,



If I were to guess, a possible source for this error is the permissions on the folder, but this is only a guess.



The reason I say this is cuz I have the similar script for "adding" a new contact, which works.  But when I copied the "Add" script to a production folder, it stopped working with similar errors.  The solution was to (a) delete the production folder and (b) rename the development folder to the name of the production folder.  Weird, but the script now works...


Tom

Highlighted
Employee

Permissions

I am glad that you were able to resolve the issue you were experiencing. The warning message that you received is typically caused by permissions as you had suggested, and that is where I would begin troubleshooting. If your development folder had different permissions than your production folder, this could explain why your solution fixed the issue.

David J

Highlighted
Participant

Warning: fwrite(), fseek():, curl_setopt(), fclose() message w/E

Hi David,


Oops, you misunderstood, the problem is not solved.


When I copied the files to the production folder, I created a second problem, which was solved by renaming the folders.


The original still exists, hence I need some help.  However, when I was having the problems with the second issue,I looked at the permissions of the two folders and the looked identical.  Hence I have no clue why the renaming worked...  It's FM...


So back to the original problem, do you have any clue what could be causing this issue? i.e. What should the permission be on the folder containing the scripts?


Tom

Highlighted
Participant

Warning: fwrite(), fseek():, curl_setopt(), fclose() message w/E

Hi David,


As a test on the development folder, I changed the permissions from 755 to 777.  No effect, I still get the same errors.


Tom

Highlighted
Participant

Warning: fwrite(), fseek():, curl_setopt(), fclose() message w/E

Hi David,


As a test on the development folder, I changed the permissions from 755 to 777.  No effect, I still get the same errors.


Tom

Highlighted
Employee

Permissions

Sorry for the misunderstanding Tom. Since your POST (creating a new contact) appears to be working fine, but it is the PUT you are having issues with, I would like to modify a few parts of the cc_class.php file, specifically the doServerCall function.


 


Let's change:


       curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type:application/atom+xml"));


To:


      curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type:application/atom+xml", 'Content-Length: ' . strlen($parameter)));


 


And replace: 


                case 'PUT':

                    $tmpfile = tmpfile();

                    fwrite($tmpfile, $parameter);

                    fseek($tmpfile, 0);

                    curl_setopt($ch, CURLOPT_INFILE, $tmpfile);

                    curl_setopt($ch, CURLOPT_PUT, 1);

                    curl_setopt($ch, CURLOPT_INFILESIZE, strlen($parameter));

                    fclose($tmpfile);

                    break;


 


With:


                    case 'PUT':

                    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");

                    curl_setopt($ch, CURLOPT_POSTFIELDS, $parameter);

                    break;

 

David J

Highlighted
Participant

Warning: fwrite(), fseek():, curl_setopt(), fclose() message w/

Hi David,


Thank you - That appears to have done the trick, it now works in the development site without any problems.


Again, thank you for your quick support.


Tom

Highlighted
Participant

Warning: fwrite(), fseek():, curl_setopt(), fclose() message w/E

Hi David,


This case can be closed, your solution worked and it is published...


Thank you for your help.


Tom

Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured