I've seen this question posted before using search, however no one seemed to provide a working solution that I could tell, or the user just ended up writing "it works now for some reason."
Anyway, the problem is when I try to upload a file, it is always less than or equal to 1 byte in size. Here's the code:
I have no idea what the issue is, but it's driving me absolutely insane. The script doesn't even take a long time to finish when I try uploading a 10MB file. Instead it just immediately gives me the <= 1 byte error.
Any ideas? :\
Anyway, the problem is when I try to upload a file, it is always less than or equal to 1 byte in size. Here's the code:
Code:
# Upload the image
$file = $FORM{'image'}; # Image on user's computer
$cat = $FORM{'cat'}; # Category to upload image under
$totalBytes = 0;
if ($file ne "") {
$fileName = "test.jpg";
open(OUTF,">$basePath/$cat/$fileName");
while ($bytesread = read($FORM{'image'}, $buffer, 1024)) {
$totalBytes += $bytesread;
if ($totalBytes >= 102400) { close(OUTF); unlink "$basePath/$cat/$fileName"; die("Image too big.");
}
print OUTF $buffer;
}
close(OUTF);
if ($totalBytes <= 1) {
unlink "$basePath/$cat/$fileName";
die("File <= 1 byte.");
}
}
Any ideas? :\