用php加mysql做个东西,用<input type="file" name="a"/>选取完图片上传到数据库内的url是绝对路径,查询出来后显示不出来,怎么能让提交的是相对路径如(如:http://192.168.40.10:1500/php/www/pictures/1.jpeg),麻烦解释的详细点,最好有小例子,我是新手,懂的少,谢谢。

解决方案 »

  1.   

    上传时将 pictures/1.jpeg 这一点存入数据库就行了。显示时加上域名 
      

  2.   

    这个我知道,但是我不知道怎么把1.jpg截出来,$_FILES['myFile']['name']这个函数我不会用,‘myfile’和‘name’分别代表啥啊?
      

  3.   

    这个我知道,但是我不知道怎么把1.jpg截出来,$_FILES['myFile']['name']这个函数我不会用,‘myfile’和‘name’分别代表啥啊? 
      

  4.   

    我用<input type="file" name="a"/>获取的图片名,图片名为c:/php/www/pictures/1.jpg;
    我想知道用什么方法能让从<input type="file" name="a"/>中获取的文件名pictures/1.jpeg ,我知道应该获取到pictures/1.jpeg 这个文件路径,但是具体怎么得到的我我不会,麻烦能不能说点的详细点,谢谢。
      

  5.   

    本帖最后由 xuzuning 于 2013-03-14 12:52:34 编辑
      

  6.   

    $_FIELS['file']['name']这个函数我没明白,这函数怎么用啊?file和name分别代表啥?
    $picture_cut = $_FILES['picture']['name'];我这么写也没有效果啊。
      

  7.   

    刚才毛躁了表单控件 <input type="file" name="a"/>
    提交后 $_FIELS['a']['name'] 就是图片名
      

  8.   

    不好使啊,麻烦帮我看看我写的对不对?
    <?php 
    $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);
    ?>
      

  9.   

    从控件得到的值不是应该用$a = $_POST['a'];得到吗,既然用了POST方法了,还咋用$_FIELS['a']['name'];啊?
      

  10.   

    <form method="post">
    <table>
    <tr>
    <td>GoodsID:</td>
    <td>
    <input type="text" name="id" maxlength="8" onblur="value=value.replace(/[^\d]/g,'')"/>
    </td>
    </tr>
    <tr>
    <td>Barcode:</td>
    <td>
    <input type="text" name="barcode" maxlength="13" onblur="value=value.replace(/[^\d]/g,'')"/>
    </td>
    </tr>
    <tr>
    <td>GoodsName:</td>
    <td>
    <input type="text" name="goods_name"/>
    </td>
    </tr>
    <tr>
    <td>Category:</td>
    <td>
    <select name="category">
    <option value="Food">Food</option>
    <option value="Drink">Drink</option>
    <option value="Dress">Dress</option>
    <option value="Book">Book</option>
    </select>
    </td>
    </tr>
    <tr>
    <td>Specofocations:</td>
    <td>
    <input type="text" name="specifications"/>
    </td>
    </tr>
    <tr>
    <td>Manufacturers:</td>
    <td>
    <input type="text" name="manufacturers"/>
    </td>
    </tr>
    <tr>
    <td>Numbers:</td>
    <td>
    <input type="text" name="number" maxlength="6" onblur="value=value.replace(/[^\d]/g,'')"/>
    </td>
    </tr>
    <tr>
    <td>Instruction:</td>
    <td>
    <textarea rows="4" cols="10" name="instruction"></textarea>
    </td>
    </tr>
    <tr>
    <td>Picture:</td>
    <td>
    <input type="file" name="picture_url" onchange="preview()"/>
    </td>
    </tr>
    <tr>
    <td>
    <input type="submit" value="Submit"/>
    </td>
    </tr>
    </table>
    </form>
      

  11.   

    不知道你是如何学的 php
      

  12.   

    本帖最后由 xuzuning 于 2013-03-14 13:52:07 编辑
      

  13.   

    我明白了,我方法用错了,我不是想把文件上传,只是想通过<input type="file" name="picture_url" />把图片的url传给数据库,但是现在的问题是上传进去的是一个绝对路径,取出来以后页面显示不出来,我的想法是上传绝对路径(如:c:/php/wwww/pictures/1.jpg)前将url截断只上传picture/1.jpg,然后查询出来前面加上path,这样就可以显示了,但是我不知道怎么把这个绝对路径给截断然后留下我想要的东西。
      

  14.   

    $s = 'c:/php/wwww/pictures/1.jpg';
    $p = basename(dirname($s)) .'/'.basename($s);
    echo $p;pictures/1.jpg
      

  15.   


    CSDN 骨灰级玩家这么多勋章,CSDN和你有关系吧?