PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hi.. I'm new here
I already read the tutorials and useful post thread but there's no solution for my problem.
I want to ask how to change filename that got uploaded.
After I upload "he's boss.jpg", the filename at the site become "s boss.jpg".
How to change that? I can't change that after the uploading start..
After the upload finished, I access the filename using $_FILES['file']['name'], it already become "s boss.jpg".
what are you using?? It sounds like you are uploading into directory rather than DB and i think you must be using move_uploaded_file function, if not: USE IT
umm it will be like
$nameyoulike = 'boss';
$uploads_dir = /* SOME LOCATION IN UR SERVER */;
$ext = /* EXTRACT THE EXTENSION OF THE FILE */;
move_uploaded_file($_FILES["file"]["tmp_name"], "$uploads_dir/".$nameyoulike.".".$ext);
novice4eva wrote:what are you using?? It sounds like you are uploading into directory rather than DB and i think you must be using move_uploaded_file function, if not: USE IT
umm it will be like
$nameyoulike = 'boss';
$uploads_dir = /* SOME LOCATION IN UR SERVER */;
$ext = /* EXTRACT THE EXTENSION OF THE FILE */;
move_uploaded_file($_FILES["file"]["tmp_name"], "$uploads_dir/".$nameyoulike.".".$ext);
I'm using that method also, I mean, the file uploaded name is "he's boss", not I'm the only who choose the name like that, it has " ' ", so the text before " ' " got cut and become "s boss"
I want to know if someone upload file which has " ' " in the name, I can change the " ' " to " _ ", is there some way to do that?
Could you give the full code coz i just tried to upload the file with the same name and i got the file name exactly the same with single quoted and all, the scary part was when i echoed the $_FILES['file']['name'], it already had the single quotes on. Forget about that addslashes thing, i don't think that could be a solution, but then also who knows maybe it'll work for ya
novice4eva wrote:Could you give the full code coz i just tried to upload the file with the same name and i got the file name exactly the same with single quoted and all, the scary part was when i echoed the $_FILES['file']['name'], it already had the single quotes on. Forget about that addslashes thing, i don't think that could be a solution, but then also who knows maybe it'll work for ya
Humm i tried the code you gave me - it uploads the image(with that name he's boss) properly!! I am now wondering if your OS hates single quotes in the file name
try enabling error, may be it will give us some hint, put these lines at the top of your code and see what errors the script throws