Okay so a few days ago I finished a tutorial of photo gallery...I'm having problems of putting images other than jpg format...the one who made the tutorial said that you can add formats to be uploaded but he didnt show it..here was his code in his upload.php...I tried experimenting on it but I cant get it to work properly..


    <title>Album Gallery</title>
<link rel='stylesheet'  href='style.css'>
<div id='body'>
    <?php include('title_bar.php');?>
    <div id='container'>                                                                                                                              
        <h3>Upload Photos</h3>
        <form enctype='multipart/form-data' method='post'>
            if (isset($_POST['submit'])) {
                $name= $_POST['name'];

                if (empty($name) or empty($file)) {
                    echo "Please fill everything <br><br>";

                    move_uploaded_file($file_tmp,'uploads/'.$random_name. '.jpg');
                    mysql_query("INSERT into photos values('','$name','$album_id','$random_name.jpg')");
                    echo "Photo Uploaded!";

            Name: <br>
            <input type='text' name='name'>
            Select Album:<br>
            <select name='album'>
                    $query=mysql_query("SELECT id, name from albums");
                    while ($run=mysql_fetch_array($query)) {
                        echo "<option value='$album_id'>$album_name</option>";
            Select Photo: <br/>
            <input type='file' name='file'>
            <input type='submit' name='submit' value='Upload'>


I don't see a restriction in the code. I think you just have to replace the hardcoded .jpg with $_FILES['file']['type']

uhmm..what? i kinda tried it but maybe i did the wrong way..what exactly do you mean pritaes-sensei?

i kinda tried it but maybe i did the wrong way.

Show what you've tried.

move_uploaded_file($file_tmp,'uploads/'.$random_name. '.$_FILES['file']['type']');
                    mysql_query("INSERT into photos values('','$name','$album_id','$random_name.$_FILES['file']['type']')");

oh wait i got it to work..hmmm...i removed .jpeg..i am able to upload other photos..i also tried word file though it isnt necessary for this photo gallery it gioves me a rar file lol...i wonder why

                    mysql_query("INSERT into photos values('','$name','$album_id','$random_name')");
  1. rand() will return a random number so your query will be: 'uploads/12324'). You need to put a file extension after it.
  2. Also, don't use this, because you might get two image with the same random number, and they'll overwrite each other.

You can't have $variable.'.$variable etc., because it will just think your second variable is text - try this instead:


PHP will stick the inverted commas in itself, so just stick thr variables in without 's either side of them.

Yes you should.

Then just something like: <img src="<?= $photo['url']" ?>