简体   繁体   中英

Passing file path to php script

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']);

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)
...

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.

Thank you so much, Todd

EDIT: 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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM