Hello,

Cek this out: webpage

It's a static image gallery. I am trying to convert it to CMS and trying to create a CMS for the image gallery.

I do not know how to. I have all the images and thumbnail in one folder. Any clue how to?

The front end must remains the same.

Recommended Answers

All 14 Replies

Hello, I am trying to make a move. This is what I have for input_image:

<?php


    $id = isset($_POST['id']) ? $_POST['id'] : '';  
    $confirmation = isset($_POST['confirmation']) ? $_POST['confirmation'] : '';  
    $judul = isset($_POST['judul']) ? $_POST['judul'] : ''; 
    $image = isset($_POST['image']) ? $_POST['image'] : '';

    //Load berita
    if (!empty($_REQUEST['id'])){
        $result = mysql_query("SELECT * FROM gallery WHERE id =".$_REQUEST['id']) or die(mysql_error());
        $data = mysql_fetch_array($result);
        $id = $data['id'];
        $judul = $data['judul'];
        $image = $image['image'];
    }

    //Simpan berita 
    if (isset($_REQUEST['ok'])){

        if (empty($_REQUEST['id']))
            $sqlstr = "INSERT INTO gallery(judul, image) VALUES('".$judul."','".$image."')";
        else
            $sqlstr = "UPDATE gallery SET judul='".$judul."', image='".$image."' WHERE id=".$_REQUEST['id'];
        $result = mysql_query($sqlstr) or die(mysql_error());

        //Jika mode edit, maka tidak akan dikirimkan konfirmasi kepada subscriber
        //if (empty($_REQUEST['id']))   kirimEmail($idKategori, $judul, $news);
        $confirmation = ($result) ? "Data telah tersimpan." : "Gagal menyimpan data.";  
    }
    ?>
    <div align="center">
        <div style="width:800px;text-align:left;">
        <script type="text/javascript" src="../../Masterlink/cgoods/ckeditor/ckeditor.js"></script>
        <link href="../../Masterlink/cgoods/ckeditor/content.css" rel="stylesheet" type="text/css"/>
        <?php echo $confirmation;?>
        <form method="post" action="<?php echo $_SERVER['../../Masterlink/cgoods/PHP_SELF']?>">
            <input type="hidden" name="id" value="<?php echo $id; ?>"/>
            <table>
                <tr>
                    <td>Judul</td>                
                    <td><input size="30px" type="text" name="judul" value="<?php echo $judul; ?>"/></td>
                </tr>
                <tr>
                    <td>Image</td>                
                    <td><input size="30px" type="file" name="image" value="<?php echo $image; ?>"/></td>
                </tr>                
                <tr>             
                    <td><input type="submit" name="ok" value="Simpan"/></td>
              </tr>
            </table>
        </form>
        </div>
    </div>

After I input: Judul (title) and upload image and press submit.

http://localhost/RustoleumCustomCMS/Administrator/%3Cbr%20/%3E%3Cb%3ENotice%3C/Masterlink/cgoods/PHP_SELF%20in%20%3Cb%3EC:%5Cxampp%5Chtdocs%5CRustoleumCustomCMS%5Cadministrator%5Cinput_berita_static.php%3C/b%3E%20on%20line%20%3Cb%3E143%3C/b%3E%3Cbr%20/%3E

Object not found!

The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

If you think this is a server error, please contact the webmaster.
Error 404
localhost
8/30/2012 6:42:58 PM
Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1

Member Avatar for diafol

What's this?

<?php echo $_SERVER['../../Masterlink/cgoods/PHP_SELF']?>

This is not a valid url:

This may be:

<?php echo '../../Masterlink/cgoods/' . $_SERVER['PHP_SELF']; ?>

//sorry urtrivedi - simultaneous post.

change line 37 to following,

<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">

ok. It works. One more thing: how to capture the image path?

I mean the script suppose to copy the uploaded image to a certain folder where we will display the image in the gallery?

How to do so?

Also, only image type file are allowed to be uploaded.

As of now, I have these in my gallery table: id, judul(image title), image (file name), path (image path).

Member Avatar for diafol

You get all the info from the $_FILES() superglobal. If you don't have an upload script see the php manual for move_uploaded_file(): http://php.net/manual/en/function.move-uploaded-file.php or check out Tizag's site.

To limit the upload create an $allowed_extensions array and check the uploaded file's extensions against it.

You can use pathinfo http://uk.php.net/manual/en/function.pathinfo.php to get the file's extension.

You can use getimagesize() to get added info about the image: http://www.php.net/manual/en/function.getimagesize.php

Remember to use the correct enctype attribute in your form or nothing with upload.

<td><input size="30px" type="file" name="image" value="<?php echo $image; ?>"/></td>

I don't understand why you have a value here.

Member Avatar for diafol

The value suppose to show up when I edit the existing image.

I don't get you. WHy are you editing the image?

I mean changing the image with another image.

Member Avatar for diafol

You need a placeholder tag for the uploaded image since the value attribute of the file field won't work. An img tag should do:

if(isset($image))echo "<div><img src=\"$imagepath\" alt=\"last uploaded image\" title=\"{$imagetitle}\" height=\"100\" /><p>$imagepath</p></div>"; 

what is $imagepath?

Destination folder?

If not, how to get the $imagepath?

Member Avatar for diafol

It was an example. You supply your own variables.

I know I already replace $imagetitle. How to get the $imagepath? what to script to find the $imagepath ?

Is $imagepath the image path before I upload the image or the destination folder where I will be copying the uploaded image?

Member Avatar for diafol

The destination where you have uploaded it.

This is the script that I have before it. Looks like I need to add something else. what is it?

<?php

    include('../includes/koneksi.php');

    $id = isset($_POST['id']) ? $_POST['id'] : '';  
    $confirmation = isset($_POST['confirmation']) ? $_POST['confirmation'] : '';  
    $judul = isset($_POST['judul']) ? $_POST['judul'] : ''; 
    $image = isset($_POST['image']) ? $_POST['image'] : '';

    //Load berita
    if (!empty($_REQUEST['id'])){
        $result = mysql_query("SELECT * FROM gallery WHERE id =".$_REQUEST['id']) or die(mysql_error());
        $data = mysql_fetch_array($result);
        $id = $data['id'];
        $judul = $data['judul'];
        $image = $image['image'];

    }

    //Simpan berita 
    if (isset($_REQUEST['ok'])){

        if (empty($_REQUEST['id']))
            $sqlstr = "INSERT INTO gallery(judul, image) VALUES('".$judul."','".$image."')";
        else
            $sqlstr = "UPDATE gallery SET judul='".$judul."', image='".$image."' WHERE id=".$_REQUEST['id'];
        $result = mysql_query($sqlstr) or die(mysql_error());

        //Jika mode edit, maka tidak akan dikirimkan konfirmasi kepada subscriber
        //if (empty($_REQUEST['id']))   kirimEmail($idKategori, $judul, $news);
        $confirmation = ($result) ? "Data telah tersimpan." : "Gagal menyimpan data.";  
    }
    ?>
    <div align="center">
        <div style="width:800px;text-align:left;">
        <script type="text/javascript" src="../../Masterlink/cgoods/ckeditor/ckeditor.js"></script>
        <link href="../../Masterlink/cgoods/ckeditor/content.css" rel="stylesheet" type="text/css"/>
        <?php echo $confirmation;?>
        <form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
            <input type="hidden" name="id" value="<?php echo $id; ?>"/>
            <table>
                <tr>
                    <th>Judul</th>
                    <th>Image</th>
                </tr>
                <tr>
                    <td><input size="30px" type="text" name="judul" value="<?php echo $judul; ?>"/></td>
                </tr>
                <tr>
                    <td><input size="30px" type="file" name="image" value="<?php echo $image; ?>"/></td>
                </tr>                
                <tr>             
                    <td><input type="submit" name="ok" value="Simpan"/></td>
              </tr>
            </table>
        </form>
        </div>
    </div>

<?php 

    if(isset($image))echo "<div><img src=\"$imagepath\" alt=\"last uploaded image\" title=\"{$judul}\" height=\"100\" /><p>$imagepath</p></div>"; 

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.