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










share|improve this question
























  • 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















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










share|improve this question
























  • 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













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










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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


















  • 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
















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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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





































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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




















































































Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues