Results 1 to 2 of 2

Thread: trying to get the url of capture image after its saved to server with a random name

  1. #1
    Join Date
    May 2014

    trying to get the url of capture image after its saved to server with a random name

    I'm trying to fetch/get the url or entire name of image i capture from a video. I've managed to save the capture as an image in the server with a random name but cannot get the url or entire name to echo or even am able to save it to the mysql instead i keep getting the name resource 4 or 2341 number repeating inside the mysql database however a new image with a new random name appears in the server. The post img val is the capture image.

    PHP Code:

    $rawData $_POST['img_val'];
    $filteredData explode(','$rawData);
    $unencoded base64_decode($filteredData[1]);
    $randomName rand(099999);;
    //Create the image 
    $fp fopen($randomName.'.png''w');

    $mb fopen($fp'r');

    $q=mysql_query("insert into images (name) values($fp)") or die (mysql_error());

  2. #2
    Join Date
    Feb 2014
    I'm guessing $rawData is an image String, in which case, base64_decode won't return the image you're expecting as you still haven't made the image. When you enter it into your database, you're probably seeing part of the String. Assuming you know that the image will be a .png (or some other file type as long as it's known):

    PHP Code:
    $rawData $_POST['img_val']; 
    $unencoded base64_decode($rawData);
    $myImage imagecreatefromstring($unencoded);
    $myImage !== false) {
    $pngImage imagepng($myImage);
    $randomName rand(099999);
    // save it as an image
    // OR save just the image String and decode later:
         // file_put_contents($randomName."png", $unencoded);
    } else {
    // do something, the image failed

    I removed the explode line as there's really no need to break apart the image String, unless you absolutely need to do that for a specific purpose.

    If you plan to save the images, I wouldn't use a random number generator for a file name as you may end up having files with multiple images (or image Strings) and it would be hard to keep track of that in your database. Not to mention, when you read the file, you're going to have to check whether there are multiple images (or image Strings), all of which creates unnecessary work. I would be easier and more effective to increment the file names. Doing it this way, you'd just need to get the last row to find out which number to increment from when you want to insert files later on.
    Last edited by Error404; 05-17-2014 at 01:53 AM.

Thread Information

Users Browsing this Thread

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

Posting Permissions

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