Page 1 of 1

File upload to different location in the same server failed

Posted: Wed Oct 14, 2009 6:26 am
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?

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

Posted: Wed Oct 14, 2009 7:24 am
by jackpf
Code?

Have you got error reporting turned on?

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

Posted: Wed Oct 14, 2009 7:34 am
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.

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

Posted: Wed Oct 14, 2009 7:35 am
by jackpf
It's the normal PHP file upload code
What?

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

Posted: Wed Oct 14, 2009 7:46 am
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.

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

Posted: Wed Oct 14, 2009 9:41 am
by jackpf
It works for me.

What does

Code: Select all

print_r($_FILES);
display?

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

Posted: Wed Oct 14, 2009 9:52 am
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?

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

Posted: Wed Oct 14, 2009 12:27 pm
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.