We all started somewhere! Share your experience on the Get Advice: Let's Get Started Sweepstakes thread and be entered to win a $100 credit on your Constant Contact account.

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

yakmanABQ
Regular 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
yakmanABQ
Regular Participant

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

David_J
Employee

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

yakmanABQ
Regular Participant

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

yakmanABQ
Regular Participant

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

yakmanABQ
Regular Participant

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

David_J
Employee

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

yakmanABQ
Regular Participant

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

yakmanABQ
Regular Participant

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