Apache file upload to php Server

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!

Moderator: General Moderators

Post Reply
habisravi
Forum Newbie
Posts: 1
Joined: Tue Jan 28, 2014 8:12 pm

Apache file upload to php Server

Post by habisravi »

I have the following script at my php server. On executing post from my android phone.
A new file is created at "upload/" but with zero size.
i have changed the phpinfo

upload_max_filesize = 20M
post_max_size = 20M

Code: Select all

<?php
$uploaddir = './upload/';
$uploadfile = $uploaddir . basename($_FILES['file']['name']);
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
    echo "Upload Sucess.\n";
} else {
    echo "Error";
}
?>
vijayalakshmi
Forum Newbie
Posts: 8
Joined: Tue Jan 21, 2014 10:22 pm

Re: Apache file upload to php Server

Post by vijayalakshmi »

HI,
give uploaded tag as <input type="file" name="profile_image"> and
When give destinationation path fully, it will move to uploaded files to the dir(upload folder) as

Code: Select all

<?php
$destination_path = getcwd().DIRECTORY_SEPARATOR;
$uploadfile = $destination_path ."upload/". basename( $_FILES['profile_image']['name']);

if (move_uploaded_file($_FILES['file']['profile_imagee'], $uploadfile)) {
    echo "Upload Sucess.\n";
} else {
    echo "Error";
}
?>
It will work, check it...


pickle | Please use [ syntax=php ], [ syntax=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Apache file upload to php Server

Post by pickle »

What does $_FILES['file']['error'] contain? That might be giving you an error.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply