Reputation: 478
I have this code and i want to upload image with it's own name.
<?php
print_r($_FILES);
$new_image_name = "foto1.jpg";
move_uploaded_file($_FILES["file"]["tmp_name"]
,"/home/izmircic/public_html/upload/".$new_image_name);?>
I tried
<?php
print_r($_FILES);
move_uploaded_file($_FILES["file"]["name"], "/home/izmircic/public_html/upload/");
?>
but it didn't work.
Upvotes: 1
Views: 313
Reputation: 64526
The arguments to move_uploaded_file()
are the current path including filename and the destination path including filename.
It should be:
move_uploaded_file($_FILES["file"]["tmp_name"] ,"/home/izmircic/public_html/upload/".$_FILES["file"]["name"]);
You should also test for the return value, to see if it failed or not:
$moved = move_uploaded_file($_FILES["file"]["tmp_name"] ,"/home/izmircic/public_html/upload/".$_FILES["file"]["name"]);
if($moved){
echo 'success';
} else {
echo 'failed';
}
By allowing uploaded files to keep their original name, you need to validate it for whatever you're doing, for example if you only want images then check the file extension and load the image into the GD library to verify it's actually an image.
For best security it would be better to store the files outside of the document root and use a PHP script to serve them as needed, and preferably with a generated filename instead of allowing the uploader to choose.
Upvotes: 1
Reputation: 420
I think this might work for you
move_uploaded_file($_FILES["file"]["tmp_name"],".//home/izmircic/public_html/upload/".$_FILES["file"]["name"]);
Upvotes: 0
Reputation: 212
try this
<?php
print_r($_FILES);
$new_image_name = "foto1.jpg"; // remove this one and replace $_FILES["file"]["name"]
move_uploaded_file($_FILES["file"]["tmp_name"]
, "/home/izmircic/public_html/upload/" . $_FILES["file"]["name"]);
?>
Upvotes: 0