Page 1 of 1

file upload problem please help

Posted: Thu Nov 05, 2009 10:59 pm
by jaisonjustus
hai pals,

iam jaison justus from india. i have a problem in uploading files using a given path.

the code snip is:

<?php
$image = '/User/test/picture/test.png';
$path = 'art/' + basename($image);

# i need to upload this picture from client machine to my server machine.
# how can i do it
# i used move_uploaded_file() function

move_uploaded_file($image,$path);

# but its not not working how can i do it
# please help me
?>

Re: file upload problem please help

Posted: Fri Nov 06, 2009 12:22 am
by psaha
Hi, jaison justus
I think you need the following code though your need is not clear!
Try this code:

Code: Select all

<?
// File size 
$_FILESIZE="2000000";
if(isset($_POST['addfiles']))
{    
  $oldfile =  $_FILES['image']['name'];
 $uploadfile =  $_FILES['image']['name'];
 $path = 'art/' + basename($image); // remeber chmod 777 in this dir
 
       if ($_FILES['image']['size']>$_FILESIZE)
       { 
$error.="Too big!!";
       }
    if (empty($error))
       {
 move_uploaded_file($_FILES['image']['tmp_name'],"".$path."/$uploadfile");
$_OK="uploaded";
}
?>
 
// HTML Code Client side

<form name="" method="POST" enctype="multipart/form-data">
select file:<input type="file" name="image">
<input type=submit name="addfiles" value="Upload File">
</form>

Re: file upload problem please help

Posted: Fri Nov 06, 2009 12:37 am
by sureshmaharana
Use this :

$path = realpath(dirname(__FILE__) . '/../') . "/art/".basename($image);

Re: file upload problem please help

Posted: Sat Nov 07, 2009 9:33 am
by jaisonjustus
hai friends,

thanx for the reply...

pal actual i have a file path which is hard coded
which is

$file = User/test/test.png';

and i need to move it to a a folder in the server name art;

$path = 'art/';

how can i do it with out using post method..
so the problem is, i have two variable $path and $file having upload directory path in the server and other is the file actual path of a picture.
and i need to upload the picture to the server. no post actions.

the file upload.php
<?php

$file = 'User/test/test.png';
$path = 'art/';

# please fill up the upload code here using
# the above variables. no post action.
# hard coded details only


?>