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 definedUPLOADCARE_CROP = '1:1';    
</script><?phprequire_once'vendor/autoload.php';
use \Uploadcare;
$api = new Uploadcare\Api('ab11954d8908bc4b0e35', 'YOUR_SECRET_KEY');
echo$api->widget->getScriptTag();
?><head><body><formclass="form-signin-register wow fadeInUp"name="signupform"id="signupform"method="POST"action="photoupload.php"><h2class="form-signin-heading">Register now</h2><divclass="login-wrap"><p>Enter personal details</p><!-- M: The 'Choose a File' button. This also loads the widget --><?phpecho$api->widget->getInputTag('qs-file');
?><inputname="firstName"id="firstName"type="text"class="form-control"placeholder="First Name"autofocus><inputname="lastName"id="lastName"type="text"class="form-control"placeholder="Last Name"><inputname="email"id="email"onfocus="emptyElement('status')"onblur="checkemail()"onkeyup="restrict('email')"maxlength="88"type="text"class="form-control"placeholder="Email"><spanid="emailstatus"></span><selectname="gender"id="gender"onfocus="emptyElement('status')"class="form-control"><optionvalue="">Select Gender</option><optionvalue="m">Male</option><optionvalue="f">Female</option></select> ..... 
            <buttonid="signupbtn"class="btn btn-lg btn-login btn-block">Create Account </button></form><body></html>

photoupload.php

<html><head><?phprequire_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><?phpecho$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"