H
H
hollanditkzn2017-02-06 18:57:20
PHP
hollanditkzn, 2017-02-06 18:57:20

How to parse through json url?

I can't figure out how to parse the link in my case
On the server side

if (isset($_FILES["photo"])) {
    $fileName = $_FILES["photo"]["name"];
    $fileTmp=$_FILES["photo"]["tmp_name"];
    $uploadFile = "C:/OpenServer/domains/futbolka/image/img/".$fileName;
    $fileUploade = move_uploaded_file($fileTmp, $uploadFile);
    if ($fileUploade == true) {
      $response = [
      "status"=> "ok",
      "url"=> $uploadFile
      ];
      
    } else {
      $response = ["status" => "error"];
    }
    echo json_encode($response);
  }

And on the user side
$("#fileForm").on("change",function(e){
            e.preventDefault();
            var fromData = new FormData($(this)[0])

            $.ajax({
              url: "unloade.php",
              type: "POST",
              data: fromData,
              processData: false,
              contentType: false,
              success: function (data){
                var event = JSON.parse(data,function(key, value){
                  if (key == "url") return new Date(value);
                  return false;
                });
                alert(event.data.getDate());
                $("#urlAdress").attr("src", data.url);
                alert("Отправлено"+data);
              }
            });
          });

I get the following data from the server {"status":"ok","url":"C:\/OpenServer\/domains\/futbolka\/image\/img\/65.png"}
I need to throw this link to the img link.
The task is such that the user uploads a picture and it must be displayed in a certain place for editing it

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Egor Gruzdev, 2017-02-06
@egor_gruzdev

It would be necessary to give the correct url in JS:

$uploadFile = "//futbolka.ru/image/img/".$fileName;

T
tommy_13, 2017-02-07
@tommy_13

data is already an object, it does not need to be parsed

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question