Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make a variable using date() constant througout the code ? (php, drupal)
    text
    copied!<p>I have a time problem. I'm making a karaoke website were I use php for certain operations. The site is made with Drupal. My problem is that I'm using date() to make a file name of the song that is recorded. But this file name is used in two places on my page. The first place makes the file name as soon as the page loads and "echo" it to be used by an applet. The applet is to upload the file at the end when the user leaves the page after recording the song. </p> <p>The second place will use the file name when a button is pressed. This code will write the file name into a node (My Songs) to be accessed later on. So both file names have to be the same. The problem is that there is a discrepancy between the times both codes use the constant. So the name of the file written in the node My Songs is not the same as the file name that was uploaded. Because there is 4-5 minutes difference when both codes use the file name. I suppose the function: date('dmhi') is stored in the Constant and not the string (result) of the function. I tried using a variable and initializing it first with a string so it would remain a string, but it didn't work. I'm more of a C++ and VB coder, so I don't get how the variables and constants work in php. I searched the web for days and I'm not finding any answers. I hope you people can help me. Here is part of my code:</p> <p>First occurance:</p> <pre><code>&lt;?php Global $user; profile_load_profile($user); $name = $user-&gt;name; define("FILE", $title . $name . date('dmhi') . ".spx"); echo "&lt;param name=\"refreshURL\" value=\"http://english.karavid.com/node/2?sampleName=" . FILE . "&amp;movie=" . $movie . "&amp;title=" . $title . "&amp;name=" . $name . "\"&gt;\n"; echo "&lt;param name=\"uploadFileName\" value=\"" . FILE . "\"&gt;\n"; ?&gt; </code></pre> <p>Second occurance when the button is pressed: </p> <pre><code>$node1-&gt;body = substr($node1-&gt;body, 0, -8) . "&lt;tr&gt; &lt;th scope=\"col\"&gt;&lt;a href=\"http://english.karavid.com/node/2?sampleName=" . FILE . "&amp;movie=" . $movie . "&amp;title=" . $title . "&amp;name=" . $name . "\"&gt;" . $title . "&lt;/a&gt;&lt;/th&gt; &lt;th scope=\"col\"&gt;" . date('j M Y') . "&lt;/th&gt; &lt;th scope=\"col\"&gt;&lt;/th&gt; &lt;/tr&gt; &lt;/table&gt;"; node_save($node1); </code></pre> <p>Thanks in advance for any clue you can give me. </p> <p>Nathalie</p> <p><strong>EDIT:</strong></p> <p>I will try to explain better. I'm generating a page that will build some code inside an applet (a recorder for the voice). Inside that applet, I use php to make part of the applet code. That part is to make the applet upload the recording done by the user. Now, I need a file name that will be different for every user. And if the user records the same song many times during the day, the file name has to be different, so I'm using the date and time inside the file name. With the function date(); </p> <p>But that file name is generated on loading. So the file name will include the time upon loading the page. Later on when the user REALLY DO save the song, time has past but the file name that is uploaded contains the time upon loading not the time of saving. This happens because the file name is "echo"(ed) inside the applet at the time of loading the page. There is no other way I can work it around.</p> <p>But, I would like to preserve that time so that I can use it again. The thing is when I try to use the file name again, the time is no longer the same. A few minutes has passed. So the file name is not the same. And when the file name is written on another page(node or file) after the recording upon saving , it's not the same as the previous one. </p> <p>I know it's a bit complicated. But basically, I need to generate a file name with the time included inside it. And use the same file name on two occasions that will be separated with a time frame. But the file name should not change.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload