正在使用共享服务器。使用卷发时将路径和文件信息保存到mysql
我可以使用卷曲保存外部图像。但我无法将路径和文件信息保存到mysql。
<form method="post" enctype="multipart/form-data">
<table>
<tr><td><b>URL: </b> </td><td><input type="**text**" name="url" id="url" size=40></td> </tr>
<tr><th colspan=2><p><input name="upload" type="submit" class="box" id="upload" value="Upload"></p></th></tr>
</table>
</form>
<?php
set_time_limit(0);
ini_set('display_errors',true);//Just in case we get some errors, let us know....
if (isset($_POST['upload']))
{
$url = $_POST['url'];
$dir = "./files/";
$fileName = $_FILES['url']['name'];
$fileSize = $_FILES['url']['size'];
$fileType = $_FILES['url']['type'];
$filePath = $dir . $fileName;
$ch = curl_init($url);
$fp = fopen ($local_file, 'w+');
$ch = curl_init($remote_file);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_ENCODING, "");
curl_exec($ch);
curl_close($ch);
include ('db.php');
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
$query = "INSERT INTO upload2 (name, size, type, path) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$filePath')";
mysql_query($query);
mysql_close($conn);
}
当我改变输入类型,从文件到文本这是行不通的。
我需要得到的文件信息,并保存到MySQL服务器
我想您已经删除了一大堆这里卷曲代码?就这样,我很清楚,你想要的是从用户的计算机上传文件,而不是**通过cURL从URL中获取文件?或者你想选择做吗? – DaveRandom
Yaa curl评论在此处添加代码时被删除,现在添加了他们。我希望创建一个将url作为输入并将文件保存到服务器的表单。像http://example.com/example.jpg – ajk
对于这样简单的事情,我建议你使用[file_get_contents()](http://www.php.net/manual/en/function.file-get -contents.php)而不是用cURL搞乱。虽然cURL可以更精确地控制获取文件的请求,但这不是您需要的,如果您需要添加一些标题或(出于一些奇怪的原因)POST来获取文件,您可以使用流来实现上下文。 – DaveRandom