Fileupload copying file to 2. directory
I'm trying to make a file_upload of images, where I want the script to add the image to one folder called: foto, AND then I wan't it to copy the same image to: foto_ikon.
How can I do this?
I think I have to use the copy() but I don't know how to, really.
move_uploaded_file($_FILES["file"]["tmp_name"],"../foto/" . $_FILES["file"]["name"]);
This is how my move_uploaded_file looks like. 开发者_开发百科
It works perfectly.
I've tried to do it like this:
move_uploaded_file($_FILES["file"]["tmp_name"],"../foto/" . $_FILES["file"]["name"]);
copy($_FILES["file"]["name"], "../foto_ikon/");
But it's not the right way, I see.
After you've performed move_uploaded_file
there is no file at $_FILES["file"]["name"]
anymore (that is why actually function is named move_uploaded_file
)(and as DaveRandom mentioned - there was no file ever).
So if you need to copy it - do that using its real current location (the place you've moved the original file to) "../foto/" . $_FILES["file"]["name"]
like this:
copy("../foto/" . $_FILES["file"]["name"], "../foto_ikon/" . $_FILES["file"]["name"]);
Simple, you moved the file from TMP to "../foto/", copy it from there, not from your current directory:
move_uploaded_file($_FILES["file"]["tmp_name"],"../foto/" . $_FILES["file"]["name"]);
copy("../foto/" . $_FILES["file"]["name"], "../foto_ikon/" . $_FILES["file"]["name"]);
精彩评论