日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > php >内容正文

php

php在数据库中上传图片格式,如何上传图片并在php中保存数据库中的URL

發(fā)布時(shí)間:2023/12/15 php 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php在数据库中上传图片格式,如何上传图片并在php中保存数据库中的URL 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

在這個(gè)PHP代碼中我想自定義圖像上傳目的地 . 有了這個(gè)php文件,我有一個(gè)名為uploads的目錄 . 我想將我上傳的所有圖像添加到此目錄并在db中存儲(chǔ)路徑 . 我怎樣才能做到這一點(diǎn)?

// Assigning value about your server to variables for database connection

$hostname_connect= "localhost";

$database_connect= "image_upload";

$username_connect= "root";

$password_connect= "";

$connect_solning = mysql_connect($hostname_connect, $username_connect, $password_connect) or trigger_error(mysql_error(),E_USER_ERROR);

@mysql_select_db($database_connect) or die (mysql_error());

if($_POST) {

// $_FILES["file"]["error"] is HTTP File Upload variables $_FILES["file"] "file" is the name of input field you have in form tag.

if ($_FILES["file"]["error"] > 0) {

// if there is error in file uploading

echo "Return Code: " . $_FILES["file"]["error"] . "

";

} else {

// check if file already exit in "images" folder.

if (file_exists("images/" . $_FILES["file"]["name"])) {

echo $_FILES["file"]["name"] . " already exists. ";

} else {

//move_uploaded_file function will upload your image. if you want to resize image before uploading see this link http://b2atutorials.blogspot.com/2013/06/how-to-upload-and-resize-image-for.html

if(move_uploaded_file($_FILES["file"]["tmp_name"],"images/" . $_FILES["file"]["name"])) {

// If file has uploaded successfully, store its name in data base

$query_image = "insert into acc_images (image, status, acc_id) values ('".$_FILES['file']['name']."', 'display','')";

if(mysql_query($query_image)) {

echo "Stored in: " . "images/" . $_FILES["file"]["name"];

} else {

echo 'File name not stored in database';

}

}

}

}

}

?>

目前,當(dāng)我運(yùn)行上傳時(shí),我收到警告

警告:move_uploaded_file(images / 1409261668002.png):無法打開流:第29行的D:\ xampp \ htdocs \ image-upload \ index.php中沒有此類文件或目錄警告:move_uploaded_file():無法移動(dòng)'第29行D:\ xampp \ htdocs \ image-upload \ index.php中的D:\ xampp \ tmp \ php1C1F.tmp'到'images / 1409261668002.png'

總結(jié)

以上是生活随笔為你收集整理的php在数据库中上传图片格式,如何上传图片并在php中保存数据库中的URL的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。