Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

mySQL & PHP

Options
  • 26-04-2010 12:23pm
    #1
    Registered Users Posts: 15


    how do you upload a photo into mysql? Is it easier just save the file path of the photo, if so how do you insert the back slashes and semi-colons?


Comments

  • Registered Users Posts: 354 ✭✭AndrewMc


    how do you upload a photo into mysql? Is it easier just save the file path of the photo, if so how do you insert the back slashes and semi-colons?

    You can add the contents of the file as part of the SQL query string itself, or as you suggest keep them on disk and add the path. Either way, use mysql_real_escape_string() to do the dirty work.


  • Registered Users Posts: 15 sdliverpool


    AndrewMc wrote: »
    You can add the contents of the file as part of the SQL query string itself, or as you suggest keep them on disk and add the path. Either way, use mysql_real_escape_string() to do the dirty work.

    any chance of an example?


  • Registered Users Posts: 6,509 ✭✭✭daymobrew




  • Closed Accounts Posts: 20,759 ✭✭✭✭dlofnep


    I'd never store it in a DB. Rather, store a reference to where the object is located.


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    how do you upload a photo into mysql? Is it easier just save the file path of the photo, if so how do you insert the back slashes and semi-colons?

    A file path won't have back-slashes and semi-colons.

    It will have forward slashes, which can be saved as they are, and if it's a relative path then you won't need the colons.

    If all photos are stored in a single folder, you could just save the filename.

    So - upload the file into a folder on the server (e.g. into a folder called "uploads")

    Then put the filename into the database.

    P.S. Remember to either generate a unique filename or check for an existing file of the same name before doing this.


  • Advertisement
Advertisement