+ Reply to Thread
Page 2 of 5
FirstFirst 1 2 3 4 ... LastLast
Results 11 to 20 of 44

Thread: Tutorial: Storing Images in MySQL with PHP

  1. #11
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97

    Re: Tutorial: Storing Images in MySQL with PHP

    No problem.

  2. #12
    Newbie markus7258 is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    1

    Re: Tutorial: Storing Images in MySQL with PHP

    Its a great script... would it be possible to upload multiple images using one submit button only? I tried but it did not work...can you help me... show me how to do it ... thanks so much

  3. #13
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97

    Re: Tutorial: Storing Images in MySQL with PHP

    Yes, in the HTML you will need to specify the image variable as an array:

    HTML Code:
    <form enctype="multipart/form-data" action="insert.php" method="post" name="changer">
    <input name="MAX_FILE_SIZE" value="102400" type="hidden">
    <input name="image[]" accept="image/jpeg" type="file">
    <input name="image[]" accept="image/jpeg" type="file">
    <input name="image[]" accept="image/jpeg" type="file">
    <input name="image[]" accept="image/jpeg" type="file">
    <input value="Submit" type="submit">
    Notice the brackets [] on the image name (image[])? That allows you to upload multiple images via HTML. In PHP you will need to iterate through the image[] array.

  4. #14
    Newbie s1gh is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    1

    Re: Tutorial: Storing Images in MySQL with PHP

    I can't get this script to work.
    Everytime I try to upload an image, I get the following error: No image selected/uploaded.

    Is there a problem with the script?

    Edit: Stupid me. I had set the maximum filesize way too low!
    So now it's working!

    Thanks for the tutorial!

  5. #15
    Newbie shailesh is an unknown quantity at this point
    Join Date
    Dec 2008
    Posts
    1

    Smile Re: Tutorial: Storing Images in MySQL with PHP

    it is a good tutorial and code for php learner

  6. #16
    Newbie moulai is an unknown quantity at this point
    Join Date
    Feb 2009
    Posts
    2

    Re: Tutorial: Storing Images in MySQL with PHP

    hi

    retrieve the contents from database, and save it in a image formated file, call it from html

  7. #17
    Newbie ssSuave is an unknown quantity at this point
    Join Date
    Jan 2009
    Posts
    12

    Re: Tutorial: Storing Images in MySQL with PHP

    Hi I have followed all the steps and I understand the concept behind uploading and displaying an image(according to Jaan), however the image still does not display for me.

    I believe the problem is with the rights of the file or something. The reason why I think so is because i have tried uploading an image to the "uploads" folder with ftp and i can easily display it however if i upload the same exact image with the upload form and then i try to view it I get the following message "403 Forbidden".

    If it makes any difference I am using a hosted site.

    Any idea why when i upload an image with the upload form it becomes forbidden in the folder?

    Thank you Very much in advance

  8. #18
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97

    Re: Tutorial: Storing Images in MySQL with PHP

    A 403 means you can't access your PHP script. You probably have bad permissions, as you stated. chmod 755 it and try again.

  9. #19
    Newbie ssSuave is an unknown quantity at this point
    Join Date
    Jan 2009
    Posts
    12

    Re: Tutorial: Storing Images in MySQL with PHP

    So what permission rights must a folder technically have?

    Initially i had the following permissions:

    (and if you chmod 755 it this is how permissions will end up)

    Me: Read and Write
    Staff: Read only
    Everyone: Read only

    then I changed them to
    Me: Read and Write
    Staff: Read and Write
    Everyone: Read and Write

    and still get the forbidden message.

    Btw I have the following setup:

    mywebsite.com contains a folder "uploads"
    mywebsite.com contains all of my php pages

    I am trying to store just the path in the database and the actual image files
    in the upload folder.

    I host my website, so in order to make sure that my folder(uploads) had read and write access rights(which i assume are correct) i have created it on my computer and then sent it with ftp to my host. So I assume the folder still has the correct permission rights set up.


    It is weird that it works fine if i ftp and image (i am then able to view it). But if i use the uploads form it does get uploaded but i cant view it and get that "forbidden" message.

    Thank you so much for your help!

  10. #20
    Newbie ssSuave is an unknown quantity at this point
    Join Date
    Jan 2009
    Posts
    12

    Re: Tutorial: Storing Images in MySQL with PHP

    Hi Jordan! thanks for help.

    So I discovered that after I upload my image with the file upload form, the actual image's permission settings change. They change to no read rights. Therefore somewhere in my upload form i have to chmod 755 the actual file but I am not sure how to do so.

    Could you please help me out? and here is the code I have to actually upload the image:
    Code:
    if(isset($_POST['submitted']))
    {
        
        
    $uploadDir 'uploads/';
        
        
    $fileName $_FILES['userfile']['name'];
        
    $tmpName $_FILES['userfile']['tmp_name'];
        
    $fileSize $_FILES['userfile']['size'];
        
    $fileType $_FILES['userfile']['type'];
        
        
    $filePath $uploadDir $fileName;
        
        
    $result move_uploaded_file($tmpName$filePath);
        if (!
    $result)
        {
           echo 
    "Error uploading file";
        }
            
        if(!
    get_magic_quotes_gpc())
        {
           
    $fileName addslashes($fileName);
           
    $filePath addslashes($filePath);
        } 

    Last edited by Jaan; 05-31-2009 at 06:29 PM. Reason: Please use code tags when you are posting your codes!

+ Reply to Thread
Page 2 of 5
FirstFirst 1 2 3 4 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

     

Similar Threads

  1. Tutorial: PHP to MySQL
    By Jordan in forum PHP Tutorials
    Replies: 20
    Last Post: 08-28-2009, 04:22 AM
  2. John's Java Tutorial Index
    By John in forum Java Tutorials
    Replies: 0
    Last Post: 01-11-2007, 03:05 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts