nachtmsk
asked on
Uploading Binary Data using Perl
Hi,
I'm using the code below to upload images to a server.
open (OUTFILE,">>$outfile")|| warn "Error $!: cannot open $outfile";;
binmode(OUTFILE);
while ($bytesread=read($infile,$ buffer,102 4)) {
print OUTFILE $buffer;
$tmp = $bytesread;
$size = $size + $tmp;
print "$size <BR>\n";
}
close(OUTFILE);
I wrote this well over 10 years ago, but it's still works fine. That is, until I try to upload certain music (MP3) files. The filesize is zero when it gets created on the server.
Here's what works
1. Images I create and save.
2. Audio Files I create and save.
3. Video files I create and save.
Here's what doesn't work
1. Audio files that I pulled of of a CD or downloaded online.
Filesize doesn't seem to be an issues. I uploaded a 15mb image file but can't upload an 8mb mp3 file.
I'm not trying to do anything illegal here and if it doesn't work, it doesn't work .
But it seems strange I can't upload commercial audio files this way. Could it be some copy protection in the MP3 files that stops it from being copied? But I am able to make multiple copies of the file using just my desktop. Odd.
Any ideas?
Thanks,
Nacht
I'm using the code below to upload images to a server.
open (OUTFILE,">>$outfile")|| warn "Error $!: cannot open $outfile";;
binmode(OUTFILE);
while ($bytesread=read($infile,$
print OUTFILE $buffer;
$tmp = $bytesread;
$size = $size + $tmp;
print "$size <BR>\n";
}
close(OUTFILE);
I wrote this well over 10 years ago, but it's still works fine. That is, until I try to upload certain music (MP3) files. The filesize is zero when it gets created on the server.
Here's what works
1. Images I create and save.
2. Audio Files I create and save.
3. Video files I create and save.
Here's what doesn't work
1. Audio files that I pulled of of a CD or downloaded online.
Filesize doesn't seem to be an issues. I uploaded a 15mb image file but can't upload an 8mb mp3 file.
I'm not trying to do anything illegal here and if it doesn't work, it doesn't work .
But it seems strange I can't upload commercial audio files this way. Could it be some copy protection in the MP3 files that stops it from being copied? But I am able to make multiple copies of the file using just my desktop. Odd.
Any ideas?
Thanks,
Nacht
ASKER
HI,
I'm not sure how to pull places 2 and 7 out. Below is what I get when I just run stat against one of the files I'm having trouble with. I've only tried it so far on one server, Ubuntu.
File: `test.mp3'
Size: 5521085 Blocks: 10808 IO Block: 4096 regular file
Device: ca01h/51713d Inode: 4169778 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ myusername) Gid: ( 1000/ myusername)
Access: 2015-03-27 16:39:59.000000000 +0000
Modify: 2015-03-27 16:40:23.000000000 +0000
Change: 2015-03-27 16:40:23.000000000 +0000
Birth: -
I'm not sure how to pull places 2 and 7 out. Below is what I get when I just run stat against one of the files I'm having trouble with. I've only tried it so far on one server, Ubuntu.
File: `test.mp3'
Size: 5521085 Blocks: 10808 IO Block: 4096 regular file
Device: ca01h/51713d Inode: 4169778 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ myusername) Gid: ( 1000/ myusername)
Access: 2015-03-27 16:39:59.000000000 +0000
Modify: 2015-03-27 16:40:23.000000000 +0000
Change: 2015-03-27 16:40:23.000000000 +0000
Birth: -
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Teraplane: while this question has gotten a little stale, I don't see how the link you provided sheds any light on the problem. The code Nachtmsk is using is not quite the same as that in the link, but as far as I can see it's equivalent in function. Not only that, the code works fine for his other uploads.
I'd want to know more about how the value of $infile gets set, since that happens outside the code snippet we were given.
I'd also want to know if the upload also fails when the browser doing the upload is running on another OS.
Nacht, can you tell us some more about what's going on here?
I'd want to know more about how the value of $infile gets set, since that happens outside the code snippet we were given.
I'd also want to know if the upload also fails when the browser doing the upload is running on another OS.
Nacht, can you tell us some more about what's going on here?
Hi jmcg, that is fair enough. I cited that code because I remember having problems with web uploads at one stage, and this was the only material I could find that gave some insight to the issue. It helped me a lot, so thought it may be useful here too.
<off_topic> I haven't used EE for years, but the volume of questions has really dropped a lot. Would be very hard to get enough points to even get free premium status now. I'm using Stack Overflow but problems there from heavy handed moderators.</off_topic>
<off_topic> I haven't used EE for years, but the volume of questions has really dropped a lot. Would be very hard to get enough points to even get free premium status now. I'm using Stack Overflow but problems there from heavy handed moderators.</off_topic>
Does it matter which server you use?