There was a problem saving the variable. There is an Index.php file, with it ajax'om method POST is sent to the catalog.php variable file, then thanks to this file a folder is created with this name. Then another button is pressed on the index.php, thanks to which the images should be saved to the folder that you just created, but this does not happen, because the variable that is responsible for this is $catalog = "Catalog/".$_POST["saveFolder"]."/"; looks like a Catalog //, i.e. $_POST["saveFolder"] empty. Tried to save in various ways, but nothing came of it, the variable is overwritten. Is there a way to curb this problem?)

Session used, does not work anyway. I really need help. If anything, I can provide the full code of the files, it is not big.

Update

On the page index.php launched the session. Then, when I entered the folder name in the input and clicked "ok", the field value was transferred to the catalog.php file, where the folder was created. Then, I chose which pictures I want to upload and click upload. Go to the upload.php script, where we save to the created folder. This value of the created folder should be saved somewhere, so as not to be lost. In catalog.php I used the session like this

 $_SESSION['fldr'] = $_POST['saveFolder']; $safe = $_SESSION['fldr']; echo $safe; $catalog = "Catalog/".$safe."/"; echo "this is folder".$safe."!"; 

But gives out

Notice: Undefined index in catalog.php

Tried to enter a check for an empty value if (isset($_POST['saveFolder'])) $a = $_POST['saveFolder']; but gives such

Notice: Undefined variable: a

  • Do not forget to make the transferred directory basename () at least. And then they make you ... - Ipatiev

4 answers 4

Session used, does not work anyway.

Need to try again.

Because "POST overwrites" is normal behavior.
And to save state between requests, sessions should be used.
Therefore, we must not “try to curb” the obviously unsolvable problem, brushing aside from the only correct solution, but correct our mistakes.

When using sessions, the session_start() command should always be called.

  • Updated the question. - exStas
  • Did you exactly read the last sentence of my answer? - Ipatiev
  • Yes, I read. And if I write this: $_SESSION['fldr'] = $_POST['saveFolder']; , won't the session variable be overwritten every time? - exStas
  • Well, it is necessary to write with the mind, only when necessary. Do you have the same handler for all posts, or what? Whether authorization, creating a directory, uploading files - is the same code everywhere, is it being executed all the time, if only the post was? - Ipatiev
  • All I need is that the variable first participates in one script, is preserved, and then participates in the third script. I apologize if I write something wrong, my head is already swelling from all this. It seems a simple task, but it does not work out. - exStas

You first create an element, then add a picture to it? I understand correctly? Just not very clear. let's say you create an article about a car-folder, it will look like lada-2109 for example, or it is better to assign an ID. Send data - create a folder with the same name or with the Id of the article. And the server gives the answer by jason, for example {id: 123, Name: "lada-2109"} so you will know what to send to id 123. You can and through the session. Simply, maybe you incorrectly saved. Experiment just with the usual values ​​to write / read.

  • one
    Bases do not need to be used. Here it is necessary as in apple, so that everything is simple) - exStas

You can store the directory in cookies ... When creating a daddy, create a cookie; when downloading files, read the cookie.

  • To save internal server variables, only sessions should always be used. - Ipatiev

Well, as an option, you can save the name of the created folder to the <input type="hidden" name="folderName" /> when you first send it. And the next request that will be sent will already contain folderName with some value. The logic is simple, do not use any sessions, etc. But all this will work within the framework until you refresh the page completely. Well you can do with the help of DB. You create a folder, it is recorded in the database, you choose which folder to upload, the name of this folder is filled in <input name="folderName" /> and you are already working with it. This is like a variant of the right approach for your task.