code works fine...but I have a bunch of photos which are jpeg and they cant be uploaded while the other jpeg photos are able too...its really weird..oh well here's the code...

<?php
error_reporting(0);
mysql_connect('localhost','root','');
mysql_select_db('uslt');
?>
<html>
<head>

    <title>Album Gallery</title>
<link rel='stylesheet'  href='style.css'>
</head>
<body>
<div id='body'>
    <?php include('title_bar.php');?>
    <div id='container'>

        <h3>Upload Photos</h3>
        <form action="" method="POST" enctype="multipart/form-data">

<?php
    if (isset($_POST['submit'])) 
    {
        $name= $_POST['name'];
        $album_id=$_POST['album'];
        if(isset($_FILES['files']))
        {
            $errors= array();
            foreach($_FILES['files']['tmp_name'] as $key => $tmp_name )
            {
                $file_name = $key.$_FILES['files']['name'][$key];
                $file_size =$_FILES['files']['size'][$key];
                $file_tmp =$_FILES['files']['tmp_name'][$key];
                $file_type=$_FILES['files']['type'][$key];  
                if($file_size > 15000000){
                    $errors[]='File size must be less than or equal to 15 MB';
                }          
                $query="INSERT into photos(imageName,imageSize,imageType,album_id,url) VALUES('$file_name','$file_size','$file_type','$album_id', '$file_name');";
                $desired_dir="uploads";
                    if(empty($errors)==true)
                    {
                        if(is_dir($desired_dir)==false)
                        {
                            mkdir("$desired_dir", 0700);        // Create directory if it does not exist
                        }
                        if(is_dir("$desired_dir/".$file_name)==false)
                        {
                            move_uploaded_file($file_tmp,"$desired_dir/".$file_name);
                        }
                    else
                    {                                  // rename the file if another one exist
                        $new_dir="$desired_dir/".$file_name.time();
                        rename($file_tmp,$new_dir) ;               
                    }
                    mysql_query($query);           
                    }
                else
                {
                    print_r($errors);
                }
            }
                if(empty($error))
                    {
                        echo "Photos successfully uploaded";
                    }
        }
    }
?>
            <br>
            Select Album:<br>
            <select name='album'>
                <?php
                    $query=mysql_query("SELECT id, name from albums");
                    while ($run=mysql_fetch_array($query)) {
                        $album_id=$run['id'];
                        $album_name=$run['name'];
                        echo "<option value='$album_id'>$album_name</option>";
                    }
                ?>
            </select>
            <br><br>
            Select Photo: <br/>


    <input accept="image/png, image/jpeg" type="file" name="files[]" multiple/>
    <br><br>
    <input type="submit" name="submit" value="Upload"/>
</form>
</div>

</div>
</body>
</html>

Recommended Answers

All 3 Replies

they cant be uploaded while the other jpeg photos are able too

Are they perhaps bigger than the ones that aren't uploading?

yep but i already put a file size limit which is 15 MB...enough for those photos....using mysqlserver

fixed it!! I changed post max upload size in Php.ini in myapache...:3

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.