我遇到了一些可能对任何使用uploadcare.com(或类似网站)来保存用户资料图片的人有用的东西。如果问题已得到回答但我还没有找到,请提前道歉。
问题:我目前正在使用 Uploadcare.com 编写脚本。这是我使用的文档:https ://uploadcare.com/quick_start/php/
这个想法是将上传图片的 URL 与其他用户数据一起保存在数据库中。
我从
$file->getUrl();
在本地脚本上,我还可以将用户的其他所有内容保存在数据库中。
只是 URL 和 Uploadcare 的脚本不会一起工作 - 我没有保存上传图像的 URL。
脚本:
注册.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>
表格照片.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>
照片上传.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(); -->
我是否也可能弄乱了脚本的执行顺序?