Skip to content Skip to sidebar Skip to footer

Uploadcare Save URL In Database PHP

I have encountered something that might be useful to anyone using uploadcare.com (or similar) to save pictures for user profiles. Sorry in advance if the question was answered and

Solution 1:

Michael, first - I have edited your question to remove the secret key - one that you passed as the second argument to Uploadcare\Api() - it is not supposed to be seen by anyone in public.

Not sure why you embedded formphoto.php in registration.php, but I placed input tag directly in registration form and did few minor corrections, this should work:

registration.php

<html>
<head>
<script>
    //set this to true when live!
    UPLOADCARE_LIVE = false;
    UPLOADCARE_IMAGES_ONLY = true;
    //here is free croping defined
    UPLOADCARE_CROP = '1:1';    
</script>

 <?php
require_once 'vendor/autoload.php';
use \Uploadcare;
$api = new Uploadcare\Api('ab11954d8908bc4b0e35', 'YOUR_SECRET_KEY');
echo $api->widget->getScriptTag();
?>
<head>

<body>
<form class="form-signin-register wow fadeInUp" name="signupform" id="signupform"  method="POST" action="photoupload.php">
        <h2 class="form-signin-heading">Register now</h2>
        <div class="login-wrap">
            <p>Enter personal details</p>


            <!-- M: The 'Choose a File' button. This also loads the widget -->              
            <?php
echo $api->widget->getInputTag('qs-file');
?>          

            <input name="firstName" id="firstName" type="text" class="form-control" placeholder="First Name" autofocus>
            <input name="lastName" id="lastName" type="text" class="form-control" placeholder="Last Name">
            <input name="email" id="email" onfocus="emptyElement('status')" onblur="checkemail()" onkeyup="restrict('email')" maxlength="88" type="text" class="form-control" placeholder="Email"><span id="emailstatus"></span>
            <select name="gender" id="gender" onfocus="emptyElement('status')" class="form-control">
                <option value="">Select Gender</option>
                <option value="m">Male</option>
                <option value="f">Female</option>
            </select> ..... 
            <button id="signupbtn"  class="btn btn-lg btn-login btn-block">Create Account </button>
</form>
<body>
</html>

photoupload.php

<html>
<head>
<?php
require_once 'vendor/autoload.php';

useUploadcare;
$file_id = $_POST['qs-file'];
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$email = $_POST['email'];
$gender = $_POST['gender'];
$api = new UploadcareApi('ab11954d8908bc4b0e35', 'YOUR_SECRET_KEY');
$file = $api->getFile($file_id);
$file->store();
?>

</head>

<body>
<?php
echo $firstName, ' ', $lastName, ' ', $email, ' ', $gender, ' ', $file->getUrl(); ?>
<br />

</body>

You need to place both files under DOCUMENT_ROOT of your web-server and make sure it has correct access rights for both:

sudo chown www-data registration.php photoupload.php 
sudo chmod 700 registration.php photoupload.php

Post a Comment for "Uploadcare Save URL In Database PHP"