Anyone know how to do image resize and upload using PDO?

by man5
5 replies
I am learning PDO and so far I haven't seen any PDO tutorials that does all these steps.

1. Upload image
2. Resize image
3. Store filepath to database.

I have the code that does all of the above, but it's done in old mysql. It's going to take a lot of trial and error for me to convert it to PDO successfully.

So to fast track it, i am asking if any one of you know how to do it in PDO?
#image #pdo #resize #upload
  • Profile picture of the author phpg
    What PDO has to do with image upload and resize? Image upload is done using standard file upload ($_FILES), and resize with library such as gd. Then with PDO just something like this:

    $db = new PDO(...);
    $query = $db->prepare("insert into images (filepath) values (:filepath)");
    $query->bindParam(':filepath', $filepath);
    $query->execute();
    {{ DiscussionBoard.errors[8950032].message }}
    • Profile picture of the author man5
      Originally Posted by phpg View Post

      What PDO has to do with image upload and resize? Image upload is done using standard file upload (Array), and resize with library such as gd. Then with PDO just something like this:

      = new PDO(...);
      = ("insert into images (filepath) values (:filepath)");
      (':filepath', );
      ();

      I actually have it all working. The image resizes, uploads to a directory and creates a thumbnail as well, and stores the filepath in the mysql database.

      The PDO method I am using is little different. For example.
      PHP Code:
        DB::getInstance()->insert('table', array(
         
      'username' => 'Jack'
      )); 
      Anyways, there is an error when I submit the form; which includes image upload and a text field for description. Everything still uploads to database, even though this error shows up.

      I have had this before but I can not remember how I fixed it. It's called...

      Warning
      : getimagesize(): Filename cannot be empty in ...
      Signature
      {{ DiscussionBoard.errors[8950521].message }}
  • Profile picture of the author phpg
    Well, error message says that you don't correctly pass file path to getimagesize. Hard to say more not seeing the code.
    {{ DiscussionBoard.errors[8950551].message }}
  • Profile picture of the author man5
    Oh wow. I just fixed it. I just had to add another else statement. Man taking a break from a problem really helps catch the mistakes.
    Signature
    {{ DiscussionBoard.errors[8952955].message }}
    • Profile picture of the author DerekKyle
      Hey, about this PDO, how is it? I'm using resizing image with another library, but there's programming involved, you know. So I'm considering to try something new to make it easier.
      {{ DiscussionBoard.errors[9123352].message }}

Trending Topics