English 中文(简体)
需要在我现有的我的SQL印本上添加光上载
原标题:Need to add photo upload to my existing script for mySQL

我需要把照片上载到我的SQL。 我已经做了一个基本文字。 我将如何修改我现有的文字,以便我能够把每个记录插入一个形象。 图像可以是形状或大小。 非常简单。 我简化了照片表格。 希望得到任何帮助。

我在名为“磷”的照片根名录上翻了一番。

<?
$order = "INSERT INTO reg_add (connect_date, 
   reg, 
   first_name, 
   last_name)

VALUES

( $_POST[connect_date] , 
      {$_POST[reg]}nv , 
      $_POST[first_name] , 
      $_POST[last_name] )";

$new_image =  photos/ .basename( $_FILES[ image ][ name ]);
    if(move_uploaded_file($_FILES[ image ][ tmp_name ], $new_image)) {
        // The images was uploaded
  } else{
header("location: reg_add_fail_IMAGE.php"); 
}

$result = mysql_query($order);
?>

表格M:

<form id="form_register" method="POST" action="reg_add.php">

   <input class="req-string bx short" type="text" name="connect_date" id="connect_date">
   <input type="hidden" name="MAX_FILE_SIZE" value="100000">
   <input class="req-string bx long caps" type="text" name="reg" id="reg">
   <input class="req-string bx long" type="text" name="first_name">
   <input class="bx long" type="text" name="last_name">

   Choose a image to upload: <input name="image" type="file">
   <input id="rbSubmit" class="rb2 rbSubmit" type="submit" value="submit">
</form>
问题回答

首先,您可使用<代码><textarea>上载图像。

<><><><>>><>>>>><>>>>>>>

<form action="savedata.php" method="POST" enctype="multipart/form-data">
    <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
    Choose a image to upload: <input name="image" type="file" /><br />
    <input type="submit" value="Submit" />
</form>

请注意,你必须列入<代码>enctype=”多部分/格式数据,以便与表格一起发送图像。

PHP When a form with FILE is sent to a PHP script the file is stored in a temporary location on the server, and the variable $_FILE is available. This variable holds the information about this file, the temporary name and the real name, size and so on.

你们需要做的是,把上载的形象提升到你想要布设的名录:

// This will be the location for the image
$new_image =  photos/ .basename( $_FILES[ image ][ name ]);

if(move_uploaded_file($_FILES[ image ][ tmp_name ], $new_image)) {
   // The images was uploaded
} else{
    // The image failed to upload
}

现在,你可以将<代码>新_image节省到数据库,以便查阅图像地点。

www.un.org/spanish/ecosoc 您应考虑的几项内容:。

  • Check if there is a file with the file name already existing
  • If there is a maximum of 1 image per database row, you could name the image using the id from database INSERT To do this you need to INSERT the data first, then get last insert id using $id = mysql_insert_id(); immediately after the INSERT query. then you incorporate this into the variable `$new_image




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签