By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,498 Members | 1,564 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,498 IT Pros & Developers. It's quick & easy.

file upload - weird!

P: n/a
Hello all,

ok, I have a file upload secton to my site, two pages, one with a
form and one that does the uploading.... some files upload fine, other
don't

an exe of 300k will upload, but a word document of 40k wont and so on,
in the php.ini a limit of 2mb is set (I haven't changed it, it's how
the file originally as, so it isn't my maths that's gone mad).

The code was taken more or less from the php manual... any iedas
people? Please? I'm going mad! And just when I was starting to enjoy
PHP :-(

Many thanks,

Amy
<?php

session_start();
$uploaddir = '/home/sites/site1/web/translation/';

$uploadfile = $uploaddir . $_FILES['userfile']['name'];
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
{

$msg = "File (" . $_FILES['userfile']['name'] . ") is valid, and
was successfully uploaded. ";
//print_r($_FILES);
session_register('content-type');
session_register('file-name');
session_register('jobid');
$jobid = time();

//rename the file with the jobid before it,

$rename = $jobid . $_FILES['userfile']['name']; //or $rename =
$username;
$file_name = $_FILES['userfile']['name'];
$read_extension = explode(".", $file_name);
$ext = $read_extension[1];
rename($file_name, $rename);

} else {

$msg = "File did not upload successfully, close window and try
again\n";
$msg = $msg . print_r($_FILES);

}
?>
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Amy Kimber wrote:

Hello all,

ok, I have a file upload secton to my site, two pages, one with a
form and one that does the uploading.... some files upload fine, other
don't

an exe of 300k will upload, but a word document of 40k wont and so on,
in the php.ini a limit of 2mb is set (I haven't changed it, it's how
the file originally as, so it isn't my maths that's gone mad).

The code was taken more or less from the php manual... any iedas
people? Please? I'm going mad! And just when I was starting to enjoy
PHP :-(

<?php

session_start();

$uploaddir = '/home/sites/site1/web/translation/';

$uploadfile = $uploaddir . $_FILES['userfile']['name'];

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
{

$msg = "File (" . $_FILES['userfile']['name'] . ") is valid, and
was successfully uploaded. ";
//print_r($_FILES);
session_register('content-type');
session_register('file-name');
session_register('jobid');
$jobid = time();

//rename the file with the jobid before it,

$rename = $jobid . $_FILES['userfile']['name']; //or $rename =
$username;
$file_name = $_FILES['userfile']['name'];
$read_extension = explode(".", $file_name);
$ext = $read_extension[1];
rename($file_name, $rename);

} else {

$msg = "File did not upload successfully, close window and try
again\n";
$msg = $msg . print_r($_FILES);

}

?>


Are you maybe uploading a file you already uploaded and renamed (shot in the
dark)?

I.E.
You upload text.doc.
text.doc moved to your upload directory.
text.doc got renamed to 1234567890text.doc.
You downloaded 1234567890text.doc to make sure it went through okay.
You upload 1234567890text.doc.
1234567890text.doc produces an error when moved to upload directory because it
already exists there.
If that's not what's happening:
What are some sample filenames of files that will and won't upload?
By "won't upload" do you mean you get your "else" error message or the file is
corrupted?
If your file is corrupted, how are you checking it?

Regards,
Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com

I have a spam filter. Please include "PHP" in the
subject line to ensure I'll get your message.
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.