图片显示问题
我想实现一个功能 就是上传A,B,C三个文件,其中包含图片和视频文件。然后要在页面上把它们显示出来,因为图片能直接显示出来,但视频没办法显示出来,我想做的是如果是图片文件,就显示原图出来,如果是视频文件,就显示B图,有什么办法能够实现吗?
我自己想的是如果存成2进制那种1010的格式的话来进行判断可不可行?
回复讨论(解决方案)
我记得HTML有个标签是可以输出媒体资源的呀,
视频也要存成 二进制????
我记得HTML有个标签是可以输出媒体资源的呀,
主要现在在A,B,C中,有可能是1是图片,2是视频,3是图片,也有可能是1是视频,2和3是图片,也有可能全是图片,我得先判断他们哪个是视频,然后做个标记,有什么比较好的方法可以推荐吗?
视频也要存成 二进制????
不是视频要存成2进制,因为ABC,3个文件中,哪个是图片哪个是视频还是未知的,我想先把它们判断出来,例如如果是视频,那i=1,如果是图片,i=0,然后把i值存成一串,例如1001这样,一时想不起该怎么存成这样
$_FILES里会有上传文件的类型呀。。根据那个判断就可以了
$_FILES里会有上传文件的类型呀。。根据那个判断就可以了
知道是根据那个来判断,我觉得我应该问的是,比如3个文件,判断是视频为1,不是视频就为0,然后我应该怎么把它弄成一串,101 这样?
简单的办法就是存成JSON,文件类型或者是什么标志对应文件路径就可以了
简单的办法就是存成JSON,文件类型或者是什么标志对应文件路径就可以了
主要现在遇到的问题是,比如同时上传3个文件,3个文件的地址是用‘,’隔开然后放在数据库同一个字段里面的,所以需要弄一个字段分别相对应的存3个文件的文件类型
视频可以使用html5的video标签显示。
每个上传 给个根据不同类型返回值,ajax或后台累计起来,放session里,最后提交三个文件,总按钮,给后台,后台从session里取值 分别存数据库里。再清空session
没太看明白你的重点是什么,如果说只是上传+展示,文件类型既然能获取到,那么展示也应该没问题啊
没太看明白你的重点是什么,如果说只是上传+展示,文件类型既然能获取到,那么展示也应该没问题啊
文件获取到了,就是我在展示的时候,该怎么通过判断去用不同标签来展示,例如,图片用img标签,可是视频用img标签不能显示的啊。就是要解决这个问题
我把数据整理成这样
array (size=13)
0 =>
array (size=2)
'img_url' =>
array (size=3)
0 => string 'http://.../uploads/news/20160216/1455586975903.mov' (length=70)
1 => string 'http://.../uploads/news/20160216/1455586969431.mov' (length=70)
2 => string 'http://.../uploads/news/20160216/1455586952114.jpg' (length=70)
'is_video' =>
array (size=3)
0 => string '1' (length=1)
1 => string '1' (length=1)
2 => string '0' (length=1)
想着在页面进行volist循环,通过判断 'is_video'的值,来选择不同的标签,然后在循环的时候好像没办法形成一一对应啊。。得怎么改呢?
没太看明白你的重点是什么,如果说只是上传+展示,文件类型既然能获取到,那么展示也应该没问题啊
文件获取到了,就是我在展示的时候,该怎么通过判断去用不同标签来展示,例如,图片用img标签,可是视频用img标签不能显示的啊。就是要解决这个问题
img_url和is_video2个数组的key是对应的,循环第一个数组,然后用key去第二数组取值就行
你这个问题的关键压根不是主楼描述的那些...
没太看明白你的重点是什么,如果说只是上传+展示,文件类型既然能获取到,那么展示也应该没问题啊
文件获取到了,就是我在展示的时候,该怎么通过判断去用不同标签来展示,例如,图片用img标签,可是视频用img标签不能显示的啊。就是要解决这个问题
img_url和is_video2个数组的key是对应的,循环第一个数组,然后用key去第二数组取值就行
你这个问题的关键压根不是主楼描述的那些...
哈哈哈 ,其实之前我遇到的问题是在想要怎么存进数据库判断,然后后来自己解决之后发现,读出来2个对等数组!在页面volist不了! 你说的那个方法可以volist对等数据的是吗 ?
没太看明白你的重点是什么,如果说只是上传+展示,文件类型既然能获取到,那么展示也应该没问题啊
文件获取到了,就是我在展示的时候,该怎么通过判断去用不同标签来展示,例如,图片用img标签,可是视频用img标签不能显示的啊。就是要解决这个问题
img_url和is_video2个数组的key是对应的,循环第一个数组,然后用key去第二数组取值就行
你这个问题的关键压根不是主楼描述的那些...
有没有大概示例一下?
你要这样组织数据,才能适应 volist 的要求
array (
array (
'img_url' => 'http://.../uploads/news/20160216/1455586975903.mov',
'is_video' => 1
)
array (
'img_url' => 'http://.../uploads/news/20160216/1455586969431.mov',
'is_video' => 1
),
array (
'img_url' => 'http://.../uploads/news/20160216/1455586952114.jpg',
'is_video' => 0
)
)
你要这样组织数据,才能适应 volist 的要求
array (
array (
'img_url' => 'http://.../uploads/news/20160216/1455586975903.mov',
'is_video' => 1
)
array (
'img_url' => 'http://.../uploads/news/20160216/1455586969431.mov',
'is_video' => 1
),
array (
'img_url' => 'http://.../uploads/news/20160216/1455586952114.jpg',
'is_video' => 0
)
)
array (size=13)
0 =>
array (size=10)
'id' => string '22' (length=2)
'username' => string 'ceshi' (length=5)
'contact' => string '12345678912' (length=11)
'comments' => string '哈哈' (length=6)
'address' => string '广东省' (length=36)
'img_url' => string 'http://.../uploads/news/20160216/1455586975903.mov;http://.../uploads/news/20160216/1455586969431.mov;http://.../uploads/news/20160216/1455586952114.jpg' (length=212)
'is_video' => string '1;1;0' (length=5)
我本来的那个数据格式得怎么变换成这样?我本来数据从数据库读出来后是这样的
$a = array( 'img_url' => 'http://.../uploads/news/20160216/1455586975903.mov;http://.../uploads/news/20160216/1455586969431.mov;http://.../uploads/news/20160216/1455586952114.jpg', 'is_video' => '1;1;0',);foreach(array_map(null, explode(';', $a['img_url']), explode(';', $a['is_video'])) as $v) { $b[] = array_combine(array('img_url', 'is_video'), $v);}print_r($b);
Array( [0] => Array ( [img_url] => http://.../uploads/news/20160216/1455586975903.mov [is_video] => 1 ) [1] => Array ( [img_url] => http://.../uploads/news/20160216/1455586969431.mov [is_video] => 1 ) [2] => Array ( [img_url] => http://.../uploads/news/20160216/1455586952114.jpg [is_video] => 0 ))
$a = array( 'img_url' => 'http://.../uploads/news/20160216/1455586975903.mov;http://.../uploads/news/20160216/1455586969431.mov;http://.../uploads/news/20160216/1455586952114.jpg', 'is_video' => '1;1;0',);foreach(array_map(null, explode(';', $a['img_url']), explode(';', $a['is_video'])) as $v) { $b[] = array_combine(array('img_url', 'is_video'), $v);}print_r($b);
Array( [0] => Array ( [img_url] => http://.../uploads/news/20160216/1455586975903.mov [is_video] => 1 ) [1] => Array ( [img_url] => http://.../uploads/news/20160216/1455586969431.mov [is_video] => 1 ) [2] => Array ( [img_url] => http://.../uploads/news/20160216/1455586952114.jpg [is_video] => 0 ))
这个是不是如果一开始能用Jason格式放的话 就少了这些麻烦 ?
你把数据项连接成串进行保存,本身就是败笔
你把数据项连接成串进行保存,本身就是败笔
那我应该用什么方法存进去比较恰当?
三个 url,自然存为 3 个记录
三个 url,自然存为 3 个记录
然后存数据库的时候呢?就是3个url是同一个人所占有的,我该怎么处理?
当然要同时保存宿主标识啦
当然要同时保存宿主标识啦
那这样的话是不是就得弄2张表了,一张存内容,一张是存URL的?
因为一个人提交的还包含其他信息,我是想放在同一条记录。
还有就是,因为url里面有视频有图片,那在模板那里是不是就只能通过这种方法判断他们的文件类型来选择标签 ?
按照 数据库范式,应该是的

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

Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

The enumeration function in PHP8.1 enhances the clarity and type safety of the code by defining named constants. 1) Enumerations can be integers, strings or objects, improving code readability and type safety. 2) Enumeration is based on class and supports object-oriented features such as traversal and reflection. 3) Enumeration can be used for comparison and assignment to ensure type safety. 4) Enumeration supports adding methods to implement complex logic. 5) Strict type checking and error handling can avoid common errors. 6) Enumeration reduces magic value and improves maintainability, but pay attention to performance optimization.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
