File upload to different location in the same server failed

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
sastha
Forum Newbie
Posts: 6
Joined: Tue Feb 05, 2008 3:42 am

File upload to different location in the same server failed

Post by sastha »

Hi,

I have a problem with file upload.

My source code is located at 'var/www/html/'. After successful file upload the files should be placed at '/opt/red5/streams/', which is also located in the same server.

But i am not able to upload the file, my requirement is to upload FLV files. I tried with move_uploaded_file() and copy() functions not only for FLV files but also for other file extenstions. But it didn't worked out for me.

Could anyone tell me what would be the solution to fix this issue?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: File upload to different location in the same server failed

Post by jackpf »

Code?

Have you got error reporting turned on?
sastha
Forum Newbie
Posts: 6
Joined: Tue Feb 05, 2008 3:42 am

Re: File upload to different location in the same server failed

Post by sastha »

jackpf wrote:Code?

Have you got error reporting turned on?
Thanks for your response. It's the normal PHP file upload code. I didn't tried with error_reporting(E_ALL); Let me try it & come back.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: File upload to different location in the same server failed

Post by jackpf »

It's the normal PHP file upload code
What?
sastha
Forum Newbie
Posts: 6
Joined: Tue Feb 05, 2008 3:42 am

Re: File upload to different location in the same server failed

Post by sastha »

Here is the source code which we are using:

Upload processing code:

Code: Select all

 
<?php
$video_path = '/opt/red5/streams/';
if($_POST['submit'] == 'Send File')
{
$imag_name =$_FILES['uploadedfile']['name'];
$storage = $video_path;
$uploadfile = "$storage" .$imag_name;
                 
try {
     if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $uploadfile)) 
    { 
    $insert_video = mysql_query("insert into videos(name) values('".$imag_name."')");
    chmod($uploadfile, 0777);
    echo $imag_name; exit;
    }
    else
   {
      echo "Video not uploaded";
    }
}
catch(Exception $e) {
  print_r($e);
}
}
?>              
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="<?=$_SERVER['PHP_SELF']?>" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="uploadedfile" type="file" />
    <input type="submit" name="submit" value="Send File" />
</form>
 
Please help me.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: File upload to different location in the same server failed

Post by jackpf »

It works for me.

What does

Code: Select all

print_r($_FILES);
display?
sastha
Forum Newbie
Posts: 6
Joined: Tue Feb 05, 2008 3:42 am

Re: File upload to different location in the same server failed

Post by sastha »

jackpf wrote:It works for me.

What does

Code: Select all

print_r($_FILES);
display?
Thanks for your reply. This is what I got,

Code: Select all

 
Array ( [uploadedfile] => Array ( 
[name] => fish.flv 
[type] => video/x-flv 
[tmp_name] => /tmp/phpRuK1O8 
[error] => 0 
[size] => 241311 ) )
 
I checked the '/tmp/' folder and the uploaded file 'phpRuK1O8' is present there. I suspect if this problem is related to file permission. What do you think?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: File upload to different location in the same server failed

Post by jackpf »

Hmm...well there's no upload error...

Try putting

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors', E_ALL);
at the top of the script.

If it's a permissions error, you should get an error message about it.
Post Reply