PHP file not found after moving it
up vote
0
down vote
favorite
I have a script that moves the file and then tries to get the file to generate a thumbnail. However, it always says that the file doesn't exist. If I try file_exists()
on the file after script execution, it seems to find it.
Pieces of my code:
// Move file, returns a path e.g. "homesambampublic_htmlsastoragefilesrxugn7OXoHNRY4J.mp4"
// This also sets file permissions to 0755
$source = $fs->move_from_tmp($filename);
// clear cache
clearstatcache(true);
// Now file_exists returns false
if(file_exists($source)){
// generate thumbnail;
}
Move_from_tmp:
public function move_from_tmp($filename){
// $this->tmp_folder = /home/sambam/public_html/ss/storage/tmp
// this->folder = /home/sambam/public_html/ss/storage/files/0
if(!is_readable($this->tmp_folder.self::DS.$filename)){ chmod($this->tmp_folder.self::DS.$filename, 0755); }
$ext = strtolower(pathinfo(basename($filename), PATHINFO_EXTENSION));
$new_filename = pathinfo($filename, PATHINFO_FILENAME);
// Move file
if(rename($this->tmp_folder.self::DS.$filename, $this->folder.self::DS.$new_filename.".".$ext)){
return $this->folder.self::DS.$new_filename.".".$ext;
}else{
return false;
}
}
This works on my local machine which is Windows but doesn't seem to work on my production machine which is Linux CentOs.
What I have also tried:
- Checked if the path has any leading/prefixed space
- File permissions
- The file is readable/writable
- And if the file exists which it does
php
|
show 5 more comments
up vote
0
down vote
favorite
I have a script that moves the file and then tries to get the file to generate a thumbnail. However, it always says that the file doesn't exist. If I try file_exists()
on the file after script execution, it seems to find it.
Pieces of my code:
// Move file, returns a path e.g. "homesambampublic_htmlsastoragefilesrxugn7OXoHNRY4J.mp4"
// This also sets file permissions to 0755
$source = $fs->move_from_tmp($filename);
// clear cache
clearstatcache(true);
// Now file_exists returns false
if(file_exists($source)){
// generate thumbnail;
}
Move_from_tmp:
public function move_from_tmp($filename){
// $this->tmp_folder = /home/sambam/public_html/ss/storage/tmp
// this->folder = /home/sambam/public_html/ss/storage/files/0
if(!is_readable($this->tmp_folder.self::DS.$filename)){ chmod($this->tmp_folder.self::DS.$filename, 0755); }
$ext = strtolower(pathinfo(basename($filename), PATHINFO_EXTENSION));
$new_filename = pathinfo($filename, PATHINFO_FILENAME);
// Move file
if(rename($this->tmp_folder.self::DS.$filename, $this->folder.self::DS.$new_filename.".".$ext)){
return $this->folder.self::DS.$new_filename.".".$ext;
}else{
return false;
}
}
This works on my local machine which is Windows but doesn't seem to work on my production machine which is Linux CentOs.
What I have also tried:
- Checked if the path has any leading/prefixed space
- File permissions
- The file is readable/writable
- And if the file exists which it does
php
Are you sure that the path returned from the move function is right?! Copy it and try to access it on terminal (ls /the/path/it/returned.mp4
)
– Elias Soares
Nov 10 at 12:50
Yes and have confirmed it
– Rust
Nov 10 at 12:51
Where ismove_from_tmp
from - is it your own code or a library?
– Darragh Enright
Nov 10 at 12:52
@LawrenceCherone I have added move_from_tmp method
– Rust
Nov 10 at 13:00
@EliasSoares after executing this code, when I tryfile_exists("pathtofile.mp4")
it returns true
– Rust
Nov 10 at 13:03
|
show 5 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a script that moves the file and then tries to get the file to generate a thumbnail. However, it always says that the file doesn't exist. If I try file_exists()
on the file after script execution, it seems to find it.
Pieces of my code:
// Move file, returns a path e.g. "homesambampublic_htmlsastoragefilesrxugn7OXoHNRY4J.mp4"
// This also sets file permissions to 0755
$source = $fs->move_from_tmp($filename);
// clear cache
clearstatcache(true);
// Now file_exists returns false
if(file_exists($source)){
// generate thumbnail;
}
Move_from_tmp:
public function move_from_tmp($filename){
// $this->tmp_folder = /home/sambam/public_html/ss/storage/tmp
// this->folder = /home/sambam/public_html/ss/storage/files/0
if(!is_readable($this->tmp_folder.self::DS.$filename)){ chmod($this->tmp_folder.self::DS.$filename, 0755); }
$ext = strtolower(pathinfo(basename($filename), PATHINFO_EXTENSION));
$new_filename = pathinfo($filename, PATHINFO_FILENAME);
// Move file
if(rename($this->tmp_folder.self::DS.$filename, $this->folder.self::DS.$new_filename.".".$ext)){
return $this->folder.self::DS.$new_filename.".".$ext;
}else{
return false;
}
}
This works on my local machine which is Windows but doesn't seem to work on my production machine which is Linux CentOs.
What I have also tried:
- Checked if the path has any leading/prefixed space
- File permissions
- The file is readable/writable
- And if the file exists which it does
php
I have a script that moves the file and then tries to get the file to generate a thumbnail. However, it always says that the file doesn't exist. If I try file_exists()
on the file after script execution, it seems to find it.
Pieces of my code:
// Move file, returns a path e.g. "homesambampublic_htmlsastoragefilesrxugn7OXoHNRY4J.mp4"
// This also sets file permissions to 0755
$source = $fs->move_from_tmp($filename);
// clear cache
clearstatcache(true);
// Now file_exists returns false
if(file_exists($source)){
// generate thumbnail;
}
Move_from_tmp:
public function move_from_tmp($filename){
// $this->tmp_folder = /home/sambam/public_html/ss/storage/tmp
// this->folder = /home/sambam/public_html/ss/storage/files/0
if(!is_readable($this->tmp_folder.self::DS.$filename)){ chmod($this->tmp_folder.self::DS.$filename, 0755); }
$ext = strtolower(pathinfo(basename($filename), PATHINFO_EXTENSION));
$new_filename = pathinfo($filename, PATHINFO_FILENAME);
// Move file
if(rename($this->tmp_folder.self::DS.$filename, $this->folder.self::DS.$new_filename.".".$ext)){
return $this->folder.self::DS.$new_filename.".".$ext;
}else{
return false;
}
}
This works on my local machine which is Windows but doesn't seem to work on my production machine which is Linux CentOs.
What I have also tried:
- Checked if the path has any leading/prefixed space
- File permissions
- The file is readable/writable
- And if the file exists which it does
php
php
edited Nov 10 at 12:58
asked Nov 10 at 12:47
Rust
3,96451944
3,96451944
Are you sure that the path returned from the move function is right?! Copy it and try to access it on terminal (ls /the/path/it/returned.mp4
)
– Elias Soares
Nov 10 at 12:50
Yes and have confirmed it
– Rust
Nov 10 at 12:51
Where ismove_from_tmp
from - is it your own code or a library?
– Darragh Enright
Nov 10 at 12:52
@LawrenceCherone I have added move_from_tmp method
– Rust
Nov 10 at 13:00
@EliasSoares after executing this code, when I tryfile_exists("pathtofile.mp4")
it returns true
– Rust
Nov 10 at 13:03
|
show 5 more comments
Are you sure that the path returned from the move function is right?! Copy it and try to access it on terminal (ls /the/path/it/returned.mp4
)
– Elias Soares
Nov 10 at 12:50
Yes and have confirmed it
– Rust
Nov 10 at 12:51
Where ismove_from_tmp
from - is it your own code or a library?
– Darragh Enright
Nov 10 at 12:52
@LawrenceCherone I have added move_from_tmp method
– Rust
Nov 10 at 13:00
@EliasSoares after executing this code, when I tryfile_exists("pathtofile.mp4")
it returns true
– Rust
Nov 10 at 13:03
Are you sure that the path returned from the move function is right?! Copy it and try to access it on terminal (
ls /the/path/it/returned.mp4
)– Elias Soares
Nov 10 at 12:50
Are you sure that the path returned from the move function is right?! Copy it and try to access it on terminal (
ls /the/path/it/returned.mp4
)– Elias Soares
Nov 10 at 12:50
Yes and have confirmed it
– Rust
Nov 10 at 12:51
Yes and have confirmed it
– Rust
Nov 10 at 12:51
Where is
move_from_tmp
from - is it your own code or a library?– Darragh Enright
Nov 10 at 12:52
Where is
move_from_tmp
from - is it your own code or a library?– Darragh Enright
Nov 10 at 12:52
@LawrenceCherone I have added move_from_tmp method
– Rust
Nov 10 at 13:00
@LawrenceCherone I have added move_from_tmp method
– Rust
Nov 10 at 13:00
@EliasSoares after executing this code, when I try
file_exists("pathtofile.mp4")
it returns true– Rust
Nov 10 at 13:03
@EliasSoares after executing this code, when I try
file_exists("pathtofile.mp4")
it returns true– Rust
Nov 10 at 13:03
|
show 5 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239104%2fphp-file-not-found-after-moving-it%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Are you sure that the path returned from the move function is right?! Copy it and try to access it on terminal (
ls /the/path/it/returned.mp4
)– Elias Soares
Nov 10 at 12:50
Yes and have confirmed it
– Rust
Nov 10 at 12:51
Where is
move_from_tmp
from - is it your own code or a library?– Darragh Enright
Nov 10 at 12:52
@LawrenceCherone I have added move_from_tmp method
– Rust
Nov 10 at 13:00
@EliasSoares after executing this code, when I try
file_exists("pathtofile.mp4")
it returns true– Rust
Nov 10 at 13:03