画像名をテーブルに保存するとき、URLのような名前を保存したい。PHPの画像名の前にURLを追加
たとえば、画像名の前に追加したいhttp://192.168.137.1/NI/uploads/のような準備完了URLがあります。
私はこの結果をしたい:http://192.168.137.1/NI/uploads/imagename.png
PHPコード:
//We will upload files to this folder
//So one thing don't forget, also create a folder named uploads inside your
project folder i.e. MyApi folder
define('UPLOAD_PATH', 'uploads/');
//connecting to database
$conn = new mysqli(DB_HOST,DB_USER,DB_PASS,DB_NAME) or die('Unable to
connect');
//An array to display the response
$response = array();
//if the call is an api call
if(isset($_GET['apicall'])){
//switching the api call
switch($_GET['apicall']){
//if it is an upload call we will upload the image
case 'uploadpic':
//first confirming that we have the image and tags in the request
parameter
if(isset($_FILES['pic']['name']) && isset($_POST['tags'])){
//uploading file and storing it to database as well
try{
move_uploaded_file($_FILES['pic']['tmp_name'], UPLOAD_PATH . $_FILES['pic']
['name']);
$stmt = $conn->prepare("INSERT INTO t_table (image,tags)
VALUES (?,?)");
$stmt->bind_param("ss", $_FILES['pic']['name'],$_POST['tags']);
if($stmt->execute()){
$response['error'] = false;
$response['message'] = 'File uploaded successfully';
}else{
throw new Exception("Could not upload file");
}
}catch(Exception $e){
$response['error'] = true;
$response['message'] = 'Could not upload file';
}
}else{
$response['error'] = true;
$response['message'] = "Required params not available";
}
なぜですか?それは生きているときに壊れます。 –
これは使えないと思います –
それはどういう意味ですか? –