[英]Download images to folder from PHP web page
我创建了一个简单的php网页,该网页在表中显示mysql数据库中的数据。 用户可以上传特定行的图像,这些图像存储在服务器上的上传文件夹中。 我希望能够添加单击特定行的按钮的功能,并且该行的图像将以该行的部件号命名的文件夹中下载到用户计算机上。 这是上传图像对话框代码:
//function to open a dialog where the user can upload an image to an existing row
$(function()
{
//$uniqueID = $('#uniqueID').val();
//opens the dialog form using the 'imgupdialog' fields outlined below
$( "#imgupdialog" ).dialog
({
autoOpen: false,
modal: true,
buttons:
{
Cancel: function()
{
$( this ).dialog( "close" );
}
},
});
//when the 'imgup' button is clicked the ID of the row will be obtained and the dialog will open
$(document).on('click', '.imgup', function()
{
//$( ".imgup" ).click(function() {
$('#uniqueID').val(($(this).attr('id')));
$("#imgupdialog").dialog( "open" );
});
});
这是上传图像的代码:
$con = mysql_connect("", "");
if (!$con) {
die("Error: " . mysql_error());
}
mysql_select_db("web", $con);
if(isset($_FILES['files']))
{
$UniqueID = $_POST['var1'];
$desired_dir="uploads/";
$errors= array();
foreach($_FILES['files']['tmp_name'] as $key => $tmp_name )
{
$file_name = $_FILES['files']['name'][$key];
$file_size =$_FILES['files']['size'][$key];
$file_tmp =$_FILES['files']['tmp_name'][$key];
$file_type=$_FILES['files']['type'][$key];
if($file_size > 2097152)
{
$errors[]='File size must be less than 2 MB';
}
$query="INSERT INTO web.PE_upload_data (ID, FILE_NAME, FILE_SIZE, FILE_TYPE) VALUES ('$UniqueID', '$file_name','$file_size','$file_type')";
if(empty($errors)==true){
if(is_dir($desired_dir)==false)
{
mkdir("$desired_dir", 0700); // Create directory if it does not exist
}
if(is_dir("$desired_dir/".$file_name)==false)
{
move_uploaded_file($file_tmp,"$desired_dir/".$file_name);
}else
{ // rename the file if another one exists
$new_dir="$desired_dir/".$file_name.time();
rename($file_tmp,$new_dir) ;
}
mysql_query($query);
}
else
{
print_r($errors);
}
}
if(empty($error))
{
echo "Success";
}
}
任何帮助将不胜感激!
正如许多人指出的那样,浏览器不允许您访问本地计算机。 如果使用Flash,Java或我最喜欢的方法,则有多种解决方法-将Silverlight保存到IsolatedStorage文件夹中。 这是一堆使用隔离存储的示例代码: http : //msdn.microsoft.com/zh-cn/library/cc265154(v=vs.95).aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.