Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7988793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:33:40+00:00 2026-06-04T12:33:40+00:00

i have simple form that uploads image to server and returns php string containing

  • 0

i have simple form that uploads image to server and returns php string containing image adress (and/or aditional html code). It is done with JqueryForm plugin. What i want: value (string) that is returned by PHP file needs to be returned to jquery, so i can use that image url to set it as bckground of some element:

Here is php file (for uplaoding image):

$path = “uploads/”;

$valid_formats = array("jpg", "png", "bmp");
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
    {
        $name = $_FILES['photoimg']['name'];
        $size = $_FILES['photoimg']['size'];

        if(strlen($name))
            {
                list($txt, $ext) = explode(".", $name);
                if(in_array($ext,$valid_formats))
                {
                if($size<(1024*1024))
                    {
                        $actual_image_name = time().substr(str_replace(" ", "_", $txt), 5).".".$ext;
                        $tmp = $_FILES['photoimg']['tmp_name'];
                        if(move_uploaded_file($tmp, $path.$actual_image_name))
                            {
                                echo $actual_image_name; //This is returned, i want thist to be somehow "converted" to jquery
                            }
                        else
                            echo "Sending failed!";
                    }
                    else
                    echo "May filesize 1 Mb!";                  
                    }
                    else
                    echo "Unknown ffile format!";   
            }

        else
            echo "Select image for sending";

        exit;
    }

And, here is jquery code for sending image:

$('#photoimg').live('change', function() {
       $("#main").html('');
$("#main").html('<img src="/uploader/loader.gif" class="vk_upload_bar" alt="Uploading...."/>');
$("#imageform").ajaxForm({
        target: '#main'
}).submit();
});

Somehow, instead of:

target: '#main'

that puts some html inside of #main, i need to make this:

   $('#main').css('background-image', 'url(' + imageUrl + ')');

where image will be assigned ti #main by css. (imageUrl is that string from php file above: $actual_image_name)

Is this possible, or at least is there some similar solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T12:33:41+00:00Added an answer on June 4, 2026 at 12:33 pm

    you need to implement success item in jquery form,
    you code must be like this
    (be sure in php u return full path of image,not need engage himself with json, with echo or print work correctly )

    $('#photoimg').live('change', function() {
       $("#main").html('');
       $("#main").html('<img src="/uploader/loader.gif" class="vk_upload_bar"       alt="Uploading...."/>');
       $("#imageform").ajaxForm({
        url : 'yourphpfile' ,
       success :function (data){
              $('#main').css('background-image', 'url(' +  data + ')');
    
        }
    
       }).submit();
        });
    

    for more information about jquery form use this link ,

    regards

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple form that uploads an image to a database. Using a
I have a simple html form that is structured something like this: <form name=test
This is probably a basic html/css question... I have a simple one-button form that
I have a simple form that looks like so <% remote_form_for post, :url =>
I have a simple form that searches through the 2000+ issues of a 3rd
I currently have a simple form that when you click the save button will
I'm creating a form. As of right now I have simple MAILTO form that
I have a simple Windows Form that hosts property controls at runtime. When the
I have started using jQuery and rails. I have made a simple form that
I have a simple form in python + pylons that submits to a controller.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.