[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

PHP Puzzler

OK, in the code below, if I have a file caled vxPRI-cgAlpha-20060512-H.mp3 or voxPRI-cgAlpha-20060512-H.mp3 it will not copy the file.  If I change the file to the star with an a like aoxPRI-cgAlpha-20060512-H.mp3, it works

Why would starting a filename with a v cause problems with the below code?

The $_GET[a] is cgAlpha and the other files all copy fine--just not the ones that start with a v

while (($file = readdir($handle))!== false) {
     if ($file != "." && $file != "..") {

          $filename = "upload/".$_GET[a]."/".$file;
         
          proecho("file $file");          
          proecho("filename $filename");
         
          $dest = $file;
          $moved_file[] = $file;

                              proecho("dest $dest");
                              proecho("moved_file $moved_file");

          $fd = fopen ($filename, "r");
          $contents = @fread ($fd, filesize ($filename));

          $desfile ="media/".$dest;
         
          proecho("desfile $desfile");
         
          if (!copy($filename, $desfile)) {
                proecho("Failed to Copy $file...<P>\n");
          }
          else {
                proecho("Artist $artist_id Uploaded $filename...<P>");
                              }
          @fclose ($fd);
     }
}
0
cglenn3932
Asked:
cglenn3932
  • 5
  • 4
1 Solution
 
cglenn3932Author Commented:
Doesn't like when the name starts with an x either....but as long as it starts with an a like axPRI-cgAlpha-20060512-H.mp3 it works.  This is nuts, what could be wrong...
0
 
Dennis MaederCommented:
Failed to copy file ...
Have you checked all causes of failure including file permissions?
Does the file exist in your destination directory? If so can it be killed without error?
Can you use move_uploaded_file() in place of copy()?
D
0
 
cglenn3932Author Commented:
its not permissions or ownership or existing file in dest dir.  No alternate functions work like move, or calling the unix coment like exec("mv filea fileb") nothing....
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Dennis MaederCommented:
Can it be copied at shell level? ftp client etc. If not, the problem is other than php.
0
 
Dennis MaederCommented:
PHP hands off to the OS to do the actual copy. If the OS fails, the error bubbles up to PHP as a simple failure - cause unknown.
The cause could be a simple as a bad file reference (e.g. misspelled file name/case/unicode character...) to permissions and quotas to file names that don't meet OS/FS conventions on file naming e.g. path reference too long. Will a small v.txt copy?
D
0
 
cglenn3932Author Commented:
It appears that I can copy in the shell as long as I rename the file.  But as long as the file does not exist...why does it allow me to copy it to a new filename?  It allows me to overwrite the other mp3 files as long as it does not start with a 'v'

Hmmm



0
 
cglenn3932Author Commented:
maybe it is the unicode issue or something....

if I am in the shell and do

cp /upload/cgAlpha/voxIM-cgAlpha-20060514-H.mp3 /media/icki.mp3

it works, but if I run

cp /upload/cgAlpha/voxIM-cgAlpha-20060514-H.mp3 /media/voxIM-cgAlpha-20060514-H.mp3

or even

cp /upload/cgAlpha/voxIM-cgAlpha-20060514-H.mp3 /media/voxIMcgAlpha20060514H.mp3

it does not work.

I THINK I FOUND IT.  I THINK my FTP client was caching and not showing that the file was indeed in the destination already.  Weird, because it didn't care about overwrinting the other MP3s, only these v ones......very weird.
0
 
cglenn3932Author Commented:
It's a bug in SmartFTP.  The file is there, the cache is empty--but it does not show up in SmartFTP

I am not gonna take the time to recreate it for them--just a very weird bug that I will work around.
0
 
Dennis MaederCommented:
But how does that explain the PHP?
Puzzling indeed!
D
0
 
BigRatCommented:
I have a customer who via my application server creates a file in a directory, writes info into it, and closes it. With a different link the server says that the file is NOT there. Indeed with ls it is definitely NOT there. But Apache shows the request, there is NO error returned and I check ALL O/S calls (open for write, write, close) for error and log them and return it to the user. No errors. This only happens with certain files, not all, since they are related to order number.

Resolution: The Linux filestore on that disk was corrupted!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now