How to configure a PHP script that generates Twitter images?
November 19, 2007 2:45 AM Subscribe
Need an assist from the PHP gurus. I'm trying to set up a PHP script that generates an image from the latest Twitter status.
I'm working off an example here.
Followed the instructions there explicitly -- tried saving the script as a PHP file and got errors like this:
Warning: filemtime(): Stat failed for twitter.txt (errno=2 - No such file or directory) in [...] on line 30
Fatal error: Call to undefined function: simplexml_load_file() in [...] on line 34
I assigned the correct permissions to the file. When I tried renaming the file as a PNG (as suggested for using on forums that require an image extension), it just gives me a corrupt PNG file when I access it. Trying both versions of .htaccess suggested in the example did not fix this.
Other possibly relevant info: test site is hosted on GoDaddy and I'm not sure if there's any PHP issues with them.
So, is there something obvious I might be missing that isn't listed on the above linked site? Is there an easier way to generate an image of Twitter updates?
I'm working off an example here.
Followed the instructions there explicitly -- tried saving the script as a PHP file and got errors like this:
Warning: filemtime(): Stat failed for twitter.txt (errno=2 - No such file or directory) in [...] on line 30
Fatal error: Call to undefined function: simplexml_load_file() in [...] on line 34
I assigned the correct permissions to the file. When I tried renaming the file as a PNG (as suggested for using on forums that require an image extension), it just gives me a corrupt PNG file when I access it. Trying both versions of .htaccess suggested in the example did not fix this.
Other possibly relevant info: test site is hosted on GoDaddy and I'm not sure if there's any PHP issues with them.
So, is there something obvious I might be missing that isn't listed on the above linked site? Is there an easier way to generate an image of Twitter updates?
Beyond the need for simpleXML, as missmagenta points out, a simple 'if file_exists()' statement will let you avoid the warning.
posted by Smoosh Faced Lion at 3:55 AM on November 19, 2007
posted by Smoosh Faced Lion at 3:55 AM on November 19, 2007
Response by poster: Thanks for that, I dug around Godaddy's site and found that it wanted a .PHP5 extension to execute correctly. So, I can get it to work from twitter.PHP5, but now I'm having trouble with renaming it as twitter.png and working correctly.
When I do this and load the PNG file, it just echoes the PHP code to the browser window instead of opening a graphic file (which works fine as a .PHP5 file).
I'm using this in the directory's .htaccess file:
AddType x-mapp-php5 .png
Should I try something else?
posted by empyrean at 5:08 AM on November 19, 2007
When I do this and load the PNG file, it just echoes the PHP code to the browser window instead of opening a graphic file (which works fine as a .PHP5 file).
I'm using this in the directory's .htaccess file:
AddType x-mapp-php5 .png
Should I try something else?
posted by empyrean at 5:08 AM on November 19, 2007
You don't necessarily need to rename it to .png - this is only if you're trying to use it somewhere that restricts non-image file extensions in image tags.
Where are you trying to use it? Have you tried just using the php5 file? eg. <>
If you really need it to be a .png file then you could try also adding
AddHandler x-mapp-php5 .png or AddType application/x-httpd-php5 .png
I don't know their server setup so its hard to say precisely. Do godaddy allow you to add/edit your mime types?>
posted by missmagenta at 5:49 AM on November 19, 2007
Where are you trying to use it? Have you tried just using the php5 file? eg. <>
If you really need it to be a .png file then you could try also adding
AddHandler x-mapp-php5 .png or AddType application/x-httpd-php5 .png
I don't know their server setup so its hard to say precisely. Do godaddy allow you to add/edit your mime types?>
posted by missmagenta at 5:49 AM on November 19, 2007
hmm, the eg. didn't come out right there (was fine in the live preview :( )
<img src = "twitter.php5" />
Also, where are you putting the .htaccess?
posted by missmagenta at 5:51 AM on November 19, 2007
<img src = "twitter.php5" />
Also, where are you putting the .htaccess?
posted by missmagenta at 5:51 AM on November 19, 2007
Response by poster: Yes, I do need it to be a .png for exactly the reason you listed - non-image file extensions are restricted.
Tried adding the two different suggestions into the .htaccess file and no luck. The .htaccess file is in the /status directory I created, which is the same folder as the php5/png files.
posted by empyrean at 6:01 AM on November 19, 2007
Tried adding the two different suggestions into the .htaccess file and no luck. The .htaccess file is in the /status directory I created, which is the same folder as the php5/png files.
posted by empyrean at 6:01 AM on November 19, 2007
Response by poster: Missed this one:
I don't know their server setup so its hard to say precisely. Do godaddy allow you to add/edit your mime types?
Yes, they do if you have their Host Configuration 2.0, which I checked and I do have that.
posted by empyrean at 6:03 AM on November 19, 2007
I don't know their server setup so its hard to say precisely. Do godaddy allow you to add/edit your mime types?
Yes, they do if you have their Host Configuration 2.0, which I checked and I do have that.
posted by empyrean at 6:03 AM on November 19, 2007
Best answer: Do you have a control panel or something where you can see a list of configured mime types? From that you should be able to tell exactly which line you need to use.
eg. if you have a line like
application/x-httpd-php5 .php5
then your .htaccess line would be
AddHandler application/x-httpd-php5 .png
You could try:
AddHandler x-httpd-php5 .png
although, that would be unusual, I did find a reference to using that syntax on godaddy through google - could be a typo though.
posted by missmagenta at 6:20 AM on November 19, 2007
eg. if you have a line like
application/x-httpd-php5 .php5
then your .htaccess line would be
AddHandler application/x-httpd-php5 .png
You could try:
AddHandler x-httpd-php5 .png
although, that would be unusual, I did find a reference to using that syntax on godaddy through google - could be a typo though.
posted by missmagenta at 6:20 AM on November 19, 2007
Yes, I do need it to be a .png for exactly the reason you listed - non-image file extensions are restricted
Try using mod_rewrite rules in .htaccess to map requests for file.png to file.php5
posted by Leon at 6:23 AM on November 19, 2007
Try using mod_rewrite rules in .htaccess to map requests for file.png to file.php5
posted by Leon at 6:23 AM on November 19, 2007
Response by poster: It works!
I think GoDaddy was being extremely quirky with the htaccess file and caching. Their site states new files take up to 60 minutes to become active and changes to existing files should be instantaneous, but I didn't find that to be the case.
Whatever the current one is in the cache is the one that's working now, I'll have to re-check it in an hour or two and see if I need to change it back to something else.
Thanks a lot for the help, especially from missmagenta.
posted by empyrean at 6:45 AM on November 19, 2007
I think GoDaddy was being extremely quirky with the htaccess file and caching. Their site states new files take up to 60 minutes to become active and changes to existing files should be instantaneous, but I didn't find that to be the case.
Whatever the current one is in the cache is the one that's working now, I'll have to re-check it in an hour or two and see if I need to change it back to something else.
Thanks a lot for the help, especially from missmagenta.
posted by empyrean at 6:45 AM on November 19, 2007
This thread is closed to new comments.
The other error is exactly what it says, there's no file twitter.txt, this isn't a major issue - if php has write permissions for the folder, you should only get this error the first time the script runs successfully - after that the file should exist because the script will have created it.
This is the php4 simplexml backport
posted by missmagenta at 3:17 AM on November 19, 2007