将文件路径传递到php脚本 [英] Passing file path to php script

查看:77
本文介绍了将文件路径传递到php脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过jquery/ajax将文件输入中的文件路径传递给我的php?我有一个带有文件输入按钮的html页面,然后ajax将表单"元素传递给php脚本,但是路径只是一个文件名.据我了解,这是一个安全隐患,但是我可以使用php ...

How do I pass a file path from a file input to my php via jquery/ajax? I have an html page with a file input button then ajax passes "form" elements to a php script, but the path is just a filename. As I understand it, it is a security risk, but I can get the path using php...

$img = imagecreatefromjpeg($_FILES['image']['tmp_name']);

我当时使用的是旧的普通表单,因此决定改用凉爽的ajaxy表单式设置.

I was using a plain old form and decided to switch to an cooler ajaxy form-like setup.

        /* Submit the request. */
        $.ajax
        ({
            type:     "post",
            dataType: "json",
            url:      "ajax/make_preview.php",
            data: 
            {
                filePath:   filePath,
                chartName:  chartName,
                Width:      Width,
                Height:     Height,
                Colors:     Colors,
                flossBrand: flossBrand
            },
            success: function(ResponseData)
...

有什么方法可以做到不破坏安全措施吗?还是我需要回到笨拙的形式来完成它?我不需要查看或操纵路径...只需尝试将文件放入gd图像对象即可.

Is there any way to do this without hacking around the security measures? Or do I need to go back to a crappy form to accomplish it? I do not need to see or manipulate the path...just trying to get the file into a gd image object.

非常感谢你, 托德

我应该注意,我不希望jQuery进行上传.我只是想让php知道要上传的正确文件.

I should note that I do not want jQuery to do the upload. I am just trying to let php know the correct file to upload.

推荐答案

将本地文件路径传递到服务器不会帮助您上传文件.文件内容应通过请求传递,普通的ajax本身不能做到这一点.

Passing the local file path to the server doesn't help you to upload the file. The file content should be passed via request, the normal ajax cant do that by itself.

您应该尝试使用文件上传插件,例如 http://www.uploadify.com/等.

You should try file upload plugins like http://www.uploadify.com/ etc.

这篇关于将文件路径传递到php脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆