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

doc or pdf file upload to use php script

P: 57
Sir

I want to CV(doc or pdf format) upload in database. Locally its script run my server but when i hosting it doesn't work. file doesn't upload. Its display, File format is wrong, please try again. please help me................



[PHP]

$cv = $_FILES['cv']['name'];
$allowed_ext = "doc, pdf"; // These are the allowed extensions of the files that are uploaded
// Check Entension

$extension = pathinfo($HTTP_POST_FILES['cv']['name']);
$extension = $extension[extension];
$allowed_paths = explode(", ", $allowed_ext);
for($i = 0; $i < count($allowed_paths); $i++) {
if ($allowed_paths[$i] == "$extension") {
$ok = "1";
}}

if($ok == "1")
{
// Copy File
$MAX_FILE_SIZE = $HTTP_POST_VARS['MAX_FILE_SIZE'];
$time = time(); // time is used to ensure unique file name
$original_path = "current-job/".$HTTP_POST_FILES['cv']['name'];
//use for checking upload file
if (!(move_uploaded_file($HTTP_POST_FILES['cv']['tmp_name'], $original_path)))
{
$msg = "<font color='#CC0000'>Error in copy File, Please try again.</font><br><br><input name='button' type='Button' onClick='javascriot:history.go(-1)' value='Back' src='button' +>";
}
else
{
$m=$_POST['m'];
$d=$_POST['d'];
$y=$_POST['y'];
$gAppli_dob=$d;
$gAppli_dob.=" ";
$gAppli_dob.=$m;
$gAppli_dob.=", ";
$gAppli_dob.=$y;

$sql = "select * from `job_appli` where job_id='$gjob_id' and name='$gName'";
$result = mysql_query($sql) or die ("unable to $sql");
$affect = mysql_affected_rows();
if ($affect > 0)
{
$msg= "<font color='#CC0000'>Information already exists.</font><br><br><input name='button' type='Button' onClick='javascriot:history.go(-1)' value='Back' src='button' +><br>";

}
else
{
$sql = "INSERT INTO `job_appli` (`job_id`,`name`,`appli_id`,`appli_dob`,`appli_sex `,`appli_phone`,`appli_email`,`appli_fr`,`appli_or g`,`appli_posi`,`appli_ini_posi`,`cv`) VALUES('$gjob_id','$gName','$gAppli_id','$gAppli_d ob','$gAppli_sex','$gAppli_phone','$gAppli_email', '$gAppli_fr','$gAppli_org','$gAppli_posi','$gAppli _ini_posi','$cv')";
$result = mysql_query($sql) or die ("unable to $sql");
$msg = "Your information has been Submitted Successfully.<br>";
}
}
}
else
{
$msg = "<font color='#CC0000'>File format is wrong, please try again.</font><br><br><input name='button' type='Button' onClick='javascriot:history.go(-1)' value='Back' src='button' +>";
}

[/PHP]

Thanks
Noorain
May 22 '08 #1
Share this Question
Share on Google+
4 Replies


Atli
Expert 5K+
P: 5,058
Hi.

Line 6
Expand|Select|Wrap|Line Numbers
  1. // This...
  2. $extension = $extension[extension];
  3. // Should be...
  4. $extension = $extension['extension'];
  5.  
Array elements should always be quoted
Except maybe when used in strings, but thats an entirely different discussion.
May 22 '08 #2

Atli
Expert 5K+
P: 5,058
Ac couple of suggestions...

You could create an array containing the valid extensions and use the in_array function to search it for you.
Would get rid of the extra for loop there.

You seem to use $HTTP_POST_FILES and $HTTP_POST_VARS arrays ever now and then throughout your code.
They are both deprecated and should not be used.
The $_POST and $_FILES super-globals should be used instead.
May 22 '08 #3

P: 57
Hi.

Line 6
Expand|Select|Wrap|Line Numbers
  1. // This...
  2. $extension = $extension[extension];
  3. // Should be...
  4. $extension = $extension['extension'];
  5.  
Array elements should always be quoted
Except maybe when used in strings, but thats an entirely different discussion.

Thanks. but line 5 doesn't work.pathinfo()doesn't work in php 2.6.0. Please help me.
May 25 '08 #4

Atli
Expert 5K+
P: 5,058
Thanks. but line 5 doesn't work.pathinfo()doesn't work in php 2.6.0. Please help me.
Are you seriously using PHP 2?! I don't believe you! :P
That was released in like 1996, while it was still just a one man operation.

If that is the case... update to PHP 5!
I doubt anybody can help you if you are really using PHP2. It's just way to old.
May 25 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.