[英]Php File upload, rename file, and then return new filename on 'successful upload' page?
I'm trying to return the name of a file uploaded using PHP after changing image files name upon uploading it. 我试图在上传后更改图像文件名后返回使用PHP上传的文件的名称。
I thought I could create a $_session['image_name'] and then call that session up on the subsequent "successful upload" page. 我以为可以创建$ _session ['image_name'],然后在随后的“成功上传”页面上调用该会话。 I can't seem to get it correct. 我似乎无法正确理解。 I need the name so that I can store it in the mysql database. 我需要名称,以便可以将其存储在mysql数据库中。 Here's the part of my upload code that does the renaming and my attempt at creating a session: 这是我的上传代码中用于重命名和创建会话的部分:
/ /
/ make a unique filename for the uploaded file and check it is
// not taken... if it is keep trying until we find a vacant one
$now = time();
while(file_exists($uploadFilename = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name']))
{
$now++;
$_SESSION['image_name'] = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name'];
}
On my successfulUpload php page I was returning: 在我成功的php页面上,我返回:
<p>Congratulations! Your file <? echo $_Session['image_name']; ?> upload was successful</p>
I have session_start();
我有session_start();
at the very top of both the uploadProcessing code and the Successful uploads page. 位于uploadProcessing代码和“成功上传”页面的最上方。
Thanks for any help! 谢谢你的帮助!
我现在看到,在您的成功页面上,应该将$ _SESSION大写。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.