dqqxkq4047 2014-09-29 19:22
浏览 49
已采纳

通过PHP文件设置HTML属性

I'm new to PHP and seem to have ran into a problem I can't seem to get around.

I have a form on a secure page that creates a PHP file to store a text value. I named this variable $text.

The Form HTML Code:

<form action="upload_title.php" method="post">
  <label for="text">Title 1:</label>
  <input type="text" name="text" id="text"><br>
  <input type="submit" name="submit" value="Submit">
</form>

The upload_title.php then seems to store the text input as $text in filename.php:

<?php
  $var_str = var_export($_POST['text'], true);
  $var = "<?php

\$text = $var_str;

?>";
  file_put_contents('filename.php', $var);
?>

This seems to be functional as the form will generate filename.php, below is an example if I typed Store into the form input and submitted on the webpage.

<?php
  $text = 'Store';
?>

Now the issue I'm encountering is not being able to retrieve this stored as a attribute in separate html document, the index.html in my case.

This was my best approach to changing the title attribute of an image:

<a href="upload/1.jpg">
  <img src="upload/thumb.jpg" title="<?php include 'filename.php'; echo htmlspecialchars($text); ?>" alt="" class="image0">
</a>

This does not work, but I can see my JQuery detects that this is trying to be populated but does not extract the data from filename.php on the `index.htm' page.

Thank those in advance for your advice and insight, it is sincerely appreciated.

  • 写回答

1条回答 默认 最新

  • drb88830 2014-09-29 19:27
    关注

    Your issue is probably the fact that you are using an html file instead of a php file, in this case index.html.

    Your server is likely not set up by default to process .html files as php so the php does not get executed.

    Apart from that it is not a very good way to store your value as when the php does get executed, you introduce a security risk and you use a lot more storage than necessary. You'd better store the value in a database or text file.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!