duang5049 2017-05-07 22:10
浏览 83

使用url将图像存储到Mysql数据库中

i have inserting url of images into database table :first of all , the image is uploaded into a folder named uploads ( it is a sub folder of an other one named projet) in the server ( i'm using actually 000.webhost.com) , after that inserted in the table , the format of url actually is like that ( uploads/1494162719350.jpg).How Could i change the target_path( in the php code below) in order to obatin an url like(https://stationpfe.000webhostapp.com/projet/uploads/1494194541508.jpg ). here is the structure of folders in the server . structure of folders

<?php
header('Access-Control-Allow-Origin: *');
require_once("db_connect.php");
$target_path = "uploads/";
if(isset($_FILES['file']))
{
$target_path = $target_path . basename( $_FILES['file']['name']);
 
if (move_uploaded_file($_FILES['file']['tmp_name'], $target_path))  
{
//$image=basename( $_FILES["file"]["tmp_name"],".jpg"); // used to store the filename in a variable

//storind the data in your database
//$QueryInsertFile="INSERT INTO TableName SET ImageColumnName='$target_path'"; 
$query= "INSERT INTO items SET pic='$target_path'";
mysqli_query($con,$query);
echo "success";
} else 
{
echo $target_path;
echo "There was an error uploading the file, please try again!";
}
}
?>

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 孟德尔随机化结果不一致
    • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法