douchan4674 2015-06-13 12:37
浏览 32
已采纳

如何提取变量的值并重复使用该值直到被覆盖

I have a website which essentially acts as a blog / photo gallery. It comprises PHP and MYSQL. My objective is to be able to set an image on my homeimage dynamically. I have set up a form which posts a variable (which contains the relevent image filename) to my homepage file. I pick this up using the $_POST method. This works fine, but only until I refresh the homepage at which point the variable is no longer there and so, understandably, the image is no longer called. Can anyone explain how I can store the variable value i.e. the image filename, so that it can be used until such time as it is overwritten by a new image. I have tried setting up a function that returns the value, but I can't seem to hold on to it!! Any guidance would be much appreciated.

  • 写回答

2条回答 默认 最新

  • doufuxing8691 2015-06-13 12:46
    关注

    Well, you can do multiple things :

    • Store it using MySQL. Create a table that will named "configuration" for example, with one field named "homepageImage" for example. When you want to modify the image on the homepage, just update this field. When you want to get the image, just query this table and fetch this field.
    • Store it in a file on your server. You just have to overwrite the file with the new filename inside it when you want to change the image. Fetch the content of the file when you want to display the image
    • Create a symbolic link (pointing to the right image), and update the link every time you want to change the image. When you want to display the image, just put the name of the link in your img tag
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100