Elliott C. Back: Internet & Technology

configure: error: no acceptable C compiler found in $PATH

Posted in Code, Computers & Technology, Linux by Elliott Back on September 14th, 2008.

If you get the following command when trying to build a package from source on linux (Fedora 8 in my case), chances are you don’t have GCC installed:

configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.

The solution is simple, run one of the following commands to install a C compiler:

CentOS: yum -y install gcc
Fedora: up2date -i gcc

For me, this installed a few additional helper packages to get me started compiling C-code:

Installing:
 gcc                 x86_64      4.1.2-33             fedora              5.3 M
Installing for dependencies:
 cpp                 x86_64      4.1.2-33             fedora              2.9 M
 glibc-devel         x86_64      2.7-2                fedora              2.4 M
 glibc-headers       x86_64      2.7-2                fedora              599 k
 kernel-headers      x86_64      2.6.26.3-14.fc8      updates-newkey      746 k

bash: phpize: command not found

Posted in Code, Computers & Technology, Linux by Elliott Back on September 14th, 2008.

If you’ve encountered this error while trying to build a PHP plugin or an Apache extension, then you’re simply missing the PHP-Devel package on your system:

-bash: phpize: command not found

To fix this, simple issue one of the commands, depending on your linux O/S:

CentOS:  yum -y install php-devel
Fedora: up2date -i php-devel

Personally, I run yum on my fedora machine, so I would simply use it to install the package. If you don’t have yum, check out Managing Software with Yum, a great guide for sysadmins.

Using the ImageShack XML API

Posted in Code, Graphics by Elliott Back on June 1st, 2008.

If you wanted to start a free photo uploading site, but didn’t want to pay the fixed storage and bandwidth costs of Amazon’s S3 or another CDN service, you might be interested in the free ImageShack API. Currently, it allows you to upload a photo to the ImageShack service, and get back the image’s size, a photo URL, and a thumbnail URL. You can access their API by using a simple ImageShack php class:

<?php
class ImageShack
{
    var $is_url = "http://www.imageshack.us/index.php";
    var $is_result = false;
    var $is_result_parsed = false;

    public function upload( $file )
    {
        // send the image to ImageShack
        $ch = curl_init($this->is_url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 240);
        curl_setopt($ch, CURLOPT_POSTFIELDS, array( ‘xml’=>‘yes’, ‘fileupload’=>‘@’.$file ));
        curl_setopt($ch, CURLOPT_HTTPHEADER, array( ‘Expect: ’ ));
        $this->is_result = curl_exec($ch);
        curl_close($ch);

        // Parse the result
        $this->parse();
    }

    public function get_image_url()
    {
        return $this->get( "image_link" );
    }

    public function get_thumb_url()
    {
        return $this->get( "thumb_link" );
    }

    public function get_done_page()
    {
        return $this->get( "done_page" );
    }

    public function get_resolution()
    {
        return $this->get( "resolution" );
    }

    public function get_size()
    {
        return $this->get( "filesize" );
    }

    private function get( $key )
    {
        if( !$this->is_result_parsed )
            return false;

        return( $this->is_result_parsed[ $key ] );
    }

    private function parse()
    {
        if (strpos($this->is_result, '<'.'?xml version=”1.0″ encoding="iso-8859-1″?>') === false)
            $this->is_result_parsed = false;

        $xmlData = explode("\n",$this->is_result);
        $xmlr = array();

        foreach($xmlData as $xmlDatum){
            $xmlDatum = trim($xmlDatum);

            if($xmlDatum != "" && !eregi("links",$xmlDatum) && !eregi("xml",$xmlDatum)){
                $xmlDatum = str_replace(">","<",$xmlDatum);
                list($xmlNull,$xmlName,$xmlValue) = explode("<",$xmlDatum);
                $xmlr[$xmlName] = $xmlValue;
            }
        }

        $this->is_result_parsed = $xmlr;
    }
}
?>

Accepting file uploads in PHP is almost trivial. You just need a form on a web page somewhere with multipart encoding, such as:

<form enctype="multipart/form-data" id="uploadform" method="post" action="http://example.com/path/to/upload">
<input type="hidden" name="MAX_FILE_SIZE" value="1048576">
<input id="anchor_file" type="file" name="files[]" />
<input type="submit" value="" id="submitimages" name="submitimages" />
</form>

On the server side, you need to iterate through the special $_FILES array in PHP:

<?php
for($i = 1; $i < count($_FILES['files']['name']); $i++){
    $error = $_FILES['files']['error'][$i];
    if($error !== 0) break;

    $data = array(
        'name' => $_FILES['files']['name'][$i],
        'temp' => $_FILES['files']['tmp_name'][$i],
        'size' => $_FILES['files']['size'][$i]
    );

    // do something with $data now, like upload it to ImageShack
}
?>

With these bits, it’s easy to write a wraparound interface to ImageShack. In the future, I hope their API also includes being able to query for photos, comments, and ratings after uploading; at the moment I see now way to do that.

« Previous PageNext Page »