php上传图片的url
用php加mysql做个东西,用选取完图片上传到数据库内的url是绝对路径,查询出来后显示不出来,怎么能让提交的是相对路径如(如:http://192.168.40.10:1500/php/www/pictures/1.jpeg),麻烦解释的详细点,最好有小例子,我是新手,懂的少,谢谢。
回复讨论(解决方案)
上传时将 pictures/1.jpeg 这一点存入数据库就行了。
显示时加上域名
这个我知道,但是我不知道怎么把1.jpg截出来,$_FILES['myFile']['name']这个函数我不会用,‘myfile’和‘name’分别代表啥啊?
上传时将 pictures/1.jpeg 这一点存入数据库就行了。
显示时加上域名
这个我知道,但是我不知道怎么把1.jpg截出来,$_FILES['myFile']['name']这个函数我不会用,‘myfile’和‘name’分别代表啥啊?
上传时将 pictures/1.jpeg 这一点存入数据库就行了。
显示时加上域名
我用获取的图片名,图片名为c:/php/www/pictures/1.jpg;
我想知道用什么方法能让从中获取的文件名pictures/1.jpeg ,我知道应该获取到pictures/1.jpeg 这个文件路径,但是具体怎么得到的我我不会,麻烦能不能说点的详细点,谢谢。
表单控件
提交后 $_FIELS['a']['name'] 就是图片名
表单控件
提交后 $_FIELS['file']['name'] 就是图片名
$_FIELS['file']['name']这个函数我没明白,这函数怎么用啊?file和name分别代表啥?
$picture_cut = $_FILES['picture']['name'];我这么写也没有效果啊。
刚才毛躁了
表单控件
提交后 $_FIELS['a']['name'] 就是图片名
刚才毛躁了
表单控件
提交后 $_FIELS['a']['name'] 就是图片名
不好使啊,麻烦帮我看看我写的对不对?
$id = $_POST['id'];
$barcode = $_POST['barcode'];
$goods_name = $_POST['goods_name'];
$category = $_POST['category'];
$specifications = $_POST['specifications'];
$manufacturers = $_POST['manufacturers'];
$number = $_POST['number'];
$instruction = $_POST['instruction'];
$picture = $_FILES['picture_url']['name'];
$url = "http://172.17.4.96:1500/pictures/";
$picture_url = $url.$picture;
if(!$id || !$barcode || !$goods_name || !$category || !$specifications || !$manufacturers || !$number
|| !$instruction || !$picture_url){
echo 'Empty!';
exit;
}
@ $db = new mysqli('localhost','root','root','ec');
if (!$db)
{
echo 'error';
exit;
}
$query = "insert into goods values('".$id."','".$barcode."','".$goods_name."','".$category."',
'".$specifications."','".$manufacturers."','".$number."','".$instruction."','".$picture_url."')";
$result = $db->query($query);
if($result){
echo "<script>alert('success');window.self.location='insert.php';</script>";
} else {
echo "An error has occurred. The item was not added.";
}
mysql_close($db);
?>
贴出你的表单
刚才毛躁了
表单控件
提交后 $_FIELS['a']['name'] 就是图片名
从控件得到的值不是应该用$a = $_POST['a'];得到吗,既然用了POST方法了,还咋用$_FIELS['a']['name'];啊?
贴出你的表单
不知道你是如何学的 php
不知道你是如何学的 php
我刚学不长时间,我的代码问题多吗?
你的表单没有 enctype="multipart/form-data"
所以不存在文件上传
既然不是文件上传,自然也就没有 $_FIELS 了
即使是不上了 enctype="multipart/form-data"
由于你没有对 $_FILES['picture_url']['tmp_name'] 进行处理,同样和没有上传一样
本帖最后由 xuzuning 于 2013-03-14 13:52:07 编辑你的表单没有 enctype="multipart/form-data"
所以不存在文件上传
既然不是文件上传,自然也就没有 $_FIELS 了
即使是不上了 enctype="multipart/form-data"
由于你没有对 $_FILES['picture_url']['tmp_name'] 进行处……
我明白了,我方法用错了,我不是想把文件上传,只是想通过把图片的url传给数据库,但是现在的问题是上传进去的是一个绝对路径,取出来以后页面显示不出来,我的想法是上传绝对路径(如:c:/php/wwww/pictures/1.jpg)前将url截断只上传picture/1.jpg,然后查询出来前面加上path,这样就可以显示了,但是我不知道怎么把这个绝对路径给截断然后留下我想要的东西。
$s = 'c:/php/wwww/pictures/1.jpg';$p = basename(dirname($s)) .'/'.basename($s);echo $p;
PHP code
?
123
$s = 'c:/php/wwww/pictures/1.jpg'; $p = basename(dirname($s)) .'/'.basename($s); echo $p;pictures/1.jpg
谢谢,好用了。我现在在自学,所以不太系统,您有什么好书或者好的方法能推荐一下吗,谢谢。
PHP code
?
123
$s = 'c:/php/wwww/pictures/1.jpg'; $p = basename(dirname($s)) .'/'.basename($s); echo $p;pictures/1.jpg
CSDN 骨灰级玩家这么多勋章,CSDN和你有关系吧?

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.
