Topic: Manging Images and MP3 files with a MYSQL DB.

Hey guys,

I am making a database that has a couple different fields, and 2 of them need to handle images and mp3 files. Now, I looked around and found a couple of really good articles on using a BLOB type field to handle the images at least. I was going to use this until I realized my database would be huge! So, I am looking for alternative ways to do this, except I have no idea where to start! Any and all help would be appreciated.

Re: Manging Images and MP3 files with a MYSQL DB.

Yeah I wouldn't do blob data for that.

I would use a PHP upload script and then on success save the filename into the database field. Then when you pull out the data you just have to pre-pend the url/path to that filename.

I dream with an XML intereface

Re: Manging Images and MP3 files with a MYSQL DB.

though I'm sure tank is much more qualified to answer this than I am - I agree with him. I've used this method in past projects. In fact this is how Textpattern manages files and images. It's much less overhead on MySQL when serving queries.

Daniel Marino | www.iamdanielmarino.com

Re: Manging Images and MP3 files with a MYSQL DB.

Thanks tank and dmarino! I am still learning MySQL and PHP, so could you point me to anything that shows how to do this? I would greatly appreciate it!

Re: Manging Images and MP3 files with a MYSQL DB.

here's a quick post on it. should get you going in the right direction.

http://stackoverflow.com/questions/4508 … with-other

I dream with an XML intereface

Re: Manging Images and MP3 files with a MYSQL DB.

Alright, I followed the instructions on the article that tank provided, which I thought everything was going to work till this.

Warning: move_uploaded_file(images/artist-Alma De Candela.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/gulftale/public_html/GTSEntertainment/addMember.php on line 22

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/php0xeFSm' to 'images/artist-Alma De Candela.jpg' in /home/gulftale/public_html/GTSEntertainment/addMember.php on line 22
Sorry, there was a problem uploading your file.

I have given the images dir, the add.php, and the addMember.php all permissions and still nothing. I have seen something about PHP being in safe mode, but I am on a shared hosting thing, and have no idea where to look for that. Any ideas?

add.php

<form method="post" action="addMember.php" enctype="multipart/form-data">
    <p>
              Please Enter the Band Name.
            </p>
            <p>
              Band Member or Affiliates Name:
            </p>
            <input type="text" name="artist"/>
            <p>
              Please Enter the Band Members Position. Example:Drums.
            </p>
            <p>
              Band Position:
            </p>
            <input type="text" name="artistDescription"/>
            <p>
              Please Upload a Photo of the Member in gif or jpeg format. The file name should be named after the Members name. If the same file name is uploaded twice it will be overwritten! Maxium size of File is 35kb.
            </p>
            <p>
              Photo:
            </p>
            <input type="hidden" name="size" value="3500000">
            <input type="file" name="photo"><br/> 
            <center><input TYPE="submit" name="upload" title="Add data to the Database" value="Add Member"/></center>
</form>

addMember.php

<?php

//This is the directory where images will be saved
$target = "images/";
$target = $target . basename( $_FILES['photo']['name']);

//This gets all the other information from the form
$artist=$_POST['artist'];
$bandMember=$_POST['artistDescription'];
$pic=($_FILES['photo']['name']);


// Connects to your Database
mysql_connect("8.6.221.167", "gulftale_gts", "todd") or die(mysql_error()) ;
mysql_select_db("gulftale_GTSEntertainment") or die(mysql_error()) ;

//Writes the information to the database
mysql_query("INSERT INTO GTSEntertainment (artist,artistDescription,artistImage)
VALUES ('$artist', '$bandMember', '$pic')") ;

//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{

//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {

//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>

Last edited by DESTOROYER (2009-02-26 13:36:30)

Re: Manging Images and MP3 files with a MYSQL DB.

I think that maybe the move_uploaded_fil function is having path issues. try hardcoding in the path like "/home/gulftale/public_html/GTSEntertainment/images" or whatever your full path is. I think maybe it's getting confused or something in putting the path.

I dream with an XML intereface

Re: Manging Images and MP3 files with a MYSQL DB.

I changed it and still getting the same error. I pasted the error into google, and it was saying something about permissions. I have already changed my permissions on the directory to read, write and execute.

Last edited by DESTOROYER (2009-02-27 14:08:39)

Re: Manging Images and MP3 files with a MYSQL DB.

can you post your new code?

I dream with an XML intereface

Re: Manging Images and MP3 files with a MYSQL DB.

Well, I think I made a stupid error. I set the permissions on the local folder, but not the remote one. Doh!