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 I haven't found it.
The question: I'm currently working on a script with Uploadcare.com. Here is the documentation I work with: https://uploadcare.com/quick_start/php/
The idea is to save the URL of the uploaded picture together with the other user data in a database.
I get the URL from
$file->getUrl();
on a local script and I'm able to also save everything else from the user in the database.
Just the URL and the script for Uploadcare won't woork together - I don't get the URL of the uploaded image saved.
Scripts:
registration.php:
<form class="form-signin-register wow fadeInUp" name="signupform" id="signupform" onsubmit="return false;" method="POST" action="photoupload.php">
<h2 class="form-signin-heading">Register now</h2>
<div class="login-wrap">
<p>Enter personal details</p>
<input id="avatar" name="avatar" type="text" class="hidden" value="<?php echo $url; ?>">
<!-- M: The 'Choose a File' button. This also loads the widget -->
<?php include('formphoto.php'); ?>
<input id="firstName" type="text" class="form-control" placeholder="First Name" autofocus>
<input id="lastName" type="text" class="form-control" placeholder="Last Name">
<input id="email" onfocus="emptyElement('status')" onblur="checkemail()" onkeyup="restrict('email')" maxlength="88" type="text" class="form-control" placeholder="Email"><span id="emailstatus"></span>
<select 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" onclick="signup();" class="btn btn-lg btn-login btn-block" disabled>Create Account</button></form>
formphoto.php:
<?php require_once 'vendor/autoload.php';
use \Uploadcare;
$api = new Uploadcare\Api('ab11954d8908bc4b0e35', 'secretkey_removed');
?>
<?php echo $api->widget->getScriptTag(); ?>
<script>
//set this to true when live!
UPLOADCARE_LIVE = false;
UPLOADCARE_IMAGES_ONLY = true;
//here is free croping defined
UPLOADCARE_CROP = '1:1';
</script>
<form method="POST" action="photoupload.php">
<?php echo $api->widget->getInputTag('qs-file'); ?>
<!-- don't need the following line, it saves also without to uploadcare :) -->
<!-- <input type="submit" value="Save this profile picture!" /> -->
</form>
photoupload.php:
<?php
require_once 'vendor/autoload.php';
use \Uploadcare;
$file_id = $_POST['qs-file'];
$api = new Uploadcare\Api('ab11954d8908bc4b0e35', 'secretkey_removed');
$file = $api->getFile($file_id);
$file->store();
$url = $file->getUrl();
header registration.php;
?>
<!-- M: for saving the avatar picture, a hidden field. The value is the URL of pic in Uploadcare.com -->
<!-- $url = $file->getUrl(); -->
Do I maybe also mess up the order the scripts should be executed?