php上传图片的url 用php加mysql做个东西,用<input type="file" name="a"/>选取完图片上传到数据库内的url是绝对路径,查询出来后显示不出来,怎么能让提交的是相对路径如(如:http://192.168.40.10:1500/php/www/pictures/1.jpeg),麻烦解释的详细点,最好有小例子,我是新手,懂的少,谢谢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 上传时将 pictures/1.jpeg 这一点存入数据库就行了。显示时加上域名 这个我知道,但是我不知道怎么把1.jpg截出来,$_FILES['myFile']['name']这个函数我不会用,‘myfile’和‘name’分别代表啥啊? 这个我知道,但是我不知道怎么把1.jpg截出来,$_FILES['myFile']['name']这个函数我不会用,‘myfile’和‘name’分别代表啥啊? 我用<input type="file" name="a"/>获取的图片名,图片名为c:/php/www/pictures/1.jpg;我想知道用什么方法能让从<input type="file" name="a"/>中获取的文件名pictures/1.jpeg ,我知道应该获取到pictures/1.jpeg 这个文件路径,但是具体怎么得到的我我不会,麻烦能不能说点的详细点,谢谢。 本帖最后由 xuzuning 于 2013-03-14 12:52:34 编辑 $_FIELS['file']['name']这个函数我没明白,这函数怎么用啊?file和name分别代表啥?$picture_cut = $_FILES['picture']['name'];我这么写也没有效果啊。 刚才毛躁了表单控件 <input type="file" name="a"/>提交后 $_FIELS['a']['name'] 就是图片名 不好使啊,麻烦帮我看看我写的对不对?<?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);?> 从控件得到的值不是应该用$a = $_POST['a'];得到吗,既然用了POST方法了,还咋用$_FIELS['a']['name'];啊? <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> 不知道你是如何学的 php 本帖最后由 xuzuning 于 2013-03-14 13:52:07 编辑 我明白了,我方法用错了,我不是想把文件上传,只是想通过<input type="file" name="picture_url" />把图片的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;pictures/1.jpg CSDN 骨灰级玩家这么多勋章,CSDN和你有关系吧? 登录界面弹出框问题 ThinkPHP的变量传递问题 ISSET 问题 请求http(post方式)问题 留言板只能传递英文而不能传递中文。 bat调用php.exe 如何获取目标服务器响应的head 数组合并问题 怎么用get 方法给一个地址传参数??请教,谢谢 请问高手?用mail发邮件问题 关于call_user_func_array 和 引用 的一段代码 不懂求解释 请问有什么做项目规划的软件推荐的?
我想知道用什么方法能让从<input type="file" name="a"/>中获取的文件名pictures/1.jpeg ,我知道应该获取到pictures/1.jpeg 这个文件路径,但是具体怎么得到的我我不会,麻烦能不能说点的详细点,谢谢。
$picture_cut = $_FILES['picture']['name'];我这么写也没有效果啊。
提交后 $_FIELS['a']['name'] 就是图片名
<?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);
?>
<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>
$p = basename(dirname($s)) .'/'.basename($s);
echo $p;pictures/1.jpg
CSDN 骨灰级玩家这么多勋章,CSDN和你有关系吧?