从PHP网页下载图像到文件夹


Download images to folder from PHP web page

我创建了一个简单的php网页,从一个表中显示mysql数据库的数据。用户可以上传特定行的图像,这些图像存储在服务器上的上传文件夹中。我希望能够添加单击特定行的按钮的能力,并且该行的图像(s)将下载到以行部件号命名的文件夹中的用户机器上。下面是上传图片对话框代码:

//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/en-us/library/cc265154(v=vs.95).aspx