开发者

get file location of an image selected using input type"file"

开发者 https://www.devze.com 2023-02-15 05:52 出处:网络
upload.php <?php $host = \'localhost\'; $user = \'root\'; $pw = \'\'; $db = \'thepillar\'; $pic = $_GET[\'pic\'];

upload.php

<?php
$host = 'localhost'; 
$user = 'root'; 
$pw = ''; 
$db = 'thepillar'; 
$pic = $_GET['pic'];
$ext = $_GET['ext'];

mysql_connect($host,$user,$pw); 

mysql_select_db($db); 

$handle = fopen($pic, "rb");
$img = fread($handle, filesize($pic));
fclose($handle);


$pic = base64_encode($pic); 

$sql = "insert into infopics values(null,'$pic','$ext');"; 

mysql_query($sql) or die('Bad Query at '.mysql_error()); 

echo "Success! You have inserted your picture!";
?>

In the code above I am fetching $pic from my uploader.php page where I use

<input type="file" name="p开发者_运维技巧ic">

The problem here is that fopen() cannot execute its function because by using $_GET['pic'] it only retrieves the filename of the image that was chosen from the other page.

is there a way that I can retrieve the whole file path so that fopen can function?


use

$_FILES["nameOfFileControl"]["tmp_name"] to get path of file


I think you need to review your concept of file and file upload. Please Read From Here. Its basics

0

精彩评论

暂无评论...
验证码 换一张
取 消