如何上传图片到MySQL数据库使用PHP /的Flex [英] How to Upload images to mysql database Using PHP/Flex

查看:164
本文介绍了如何上传图片到MySQL数据库使用PHP /的Flex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找的净几个星期,现在并不能找到解决我的问题。

I have been searching the net for some weeks now and can't find a solution to my issue.

我在Web应用程序中使用的工作的Flex(前端) PHP / MySQL的(后端)

I'm working on a Web application using Flex(front-end) and PHP/MySql(Back-end).

现在我想允许用户上传图片,为他们的个人资料图片...我把它们上传到服务器上的目录。现在我的老板感觉,他们应该被直接存储到数据库不仅存储图片的链接,但全部内容。

Now I want to enable users to upload images for their profile Pictures... I was Uploading them to a Directory on the server. Now my Boss "feels" that they should be stored directly to the Database not only store the link of the Image but the whole content.

请帮家伙....我坚持!

Please Help guys....I'm stuck!!!

推荐答案

首先在您从上传文件的形式,你应该使用以下标签:

First of all in the form which you're uploading the file from, you should use the following the tag:

enctype="multipart/form-data" 

还需要指定该字段为下列之一:

also you need to specify that field as one of the following:

TINYBLOB   ,BLOB   ,MEDIUMBLOB   ,LONGBLOB

TINYBLOB , BLOB , MEDIUMBLOB , LONGBLOB

Finaly修改此code为你的数据库,这将做到:)

Finaly modify this code for your db and that will do :)

<?php
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
   $fileName = $_FILES['userfile']['name'];
   $tmpName  = $_FILES['userfile']['tmp_name'];
   $fileSize = $_FILES['userfile']['size'];
   $fileType = $_FILES['userfile']['type'];

   $fp      = fopen($tmpName, 'r');
   $content = fread($fp, filesize($tmpName));
   $content = addslashes($content);
   fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}

$query = "INSERT INTO upload (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";

mysql_query($query) or die('Error, query failed'); 

} 

?>

这篇关于如何上传图片到MySQL数据库使用PHP /的Flex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆