Jump to content

file upload confusion


jayjay89

Recommended Posts

hey,

I started creating this page that is suppose to upload pdf files, it opens the file upload box but when i click to submit the file nothing happens. I have checked the folder and no file goes in it. I don't know what i am doing wrong.

 

Can anyone help please?

 

<?php
session_start();
if($_SESSION['name']=="hollywincote")
{
echo "Welcome ".$_SESSION['name'];
echo "     ";
echo "<A href = \"login.php?do=logout\">logout</A>";
}
else
{
header("Location:login.php");
}

$page_title= 'Holly Wincote | Login';

include('includes/header.html');

?>
<div class="leftcontent">
<h2>Administrator Panel</h2>


<?php

//check if the form has been submitted:
if(isset($_POST['submitted'])) {

//check for an uploaded file:
if(isset($_FILES['upload'])) {

//validate the type. Should be pdf, doc or rtf.

$allowed = array('application/pdf');

if(in_array($_FILES['upload']['type'], $allowed)) {

//move the file over.
if(move_uploaded_file($_FILES['upload']['name'], "../hollywincote/uploads/{$_FILES['upload']['name']}")) {

echo '<p><em>The file has been uploaded</em></p>';

} //end of move... IF


} else {

echo '<p>Please upload a PDF.</p>';

}

} //end of isset($_FILES['upload']) IF.

//check for an error:
if($_FILES['upload']['error'] >0) {

echo '<p>The file could not be uploaded because: <strong>';

//print a message based upon the error.

switch ($_FILES['upload']['error']) {

case 1:

print 'the file exceeds the upload_max_filesize setting in php.ini.';

break;

case 2:

print 'the file exceeds the MAX_FILE_SIZE setting in the html form.';

break;

case 3:

print 'the file was only partially uploaded.';

break;

case 4:

print 'no file was uploaded.';

break;

case 6:

print 'no temporary folder was available.';

break;

case 7:

print 'unable to write to the disc.';

break;

case 8:

print 'file upload stopped.';

break;

default:

print 'a system error occured.';

break;

} //end of switch

echo '</strong></p>';


} //end of error IF.

//delete the file if it still exists
if(file_exists($_FILES['upload']['tmp_name'])) {

unlink ($_FILES['upload']['tmp_name']);

}

}//end of submitted conditional

?>

<form enctype="multipart/form-data" action="admin_panel.php" method="post">

<input type="hidden" name="MAX_FILE_SIZE" value="5242488">

<fieldset>

<legend>Select a PDF to be uploaded:</legend>

<p><b>File:</b> <input type="file" name="upload"/></p>

</fieldset>

<div align="center">

<input type="submit" name="submitted" value="submit"/>

</div>

<input type="hidden" name="submitted" value="TRUE"/>

</form>


</div><div class="clear"></div>

		</div>

<?php

include ('includes/footer.html');

?>

 

thanks

 

Janette

Link to comment
Share on other sites

You might also put some "echos" in your if statements to find out where it's stopping.  See below:

 

if (isset($_POST['submitted'])) {

 

        ECHO "1ST IF<br>";

 

//check for an uploaded file:

if (isset($_FILES['upload'])) {

 

                ECHO "2ND IF<br>";

 

//validate the type. Should be pdf, doc or rtf.

$allowed = array('application/pdf');

if (in_array($_FILES['upload']['type'], $allowed)) {

 

                        ECHO "3RD IF<br>";

 

//move the file over.

if (move_uploaded_file($_FILES['upload']['name'], "../hollywincote/uploads/{$_FILES['upload']['name']}")) {

 

                              ECHO "4TH IF<br>";

 

echo '<p><em>The file has been uploaded</em></p>';

} //end of move... IF

} else {

echo '<p>Please upload a PDF.</p>';

}

} //end of isset($_FILES['upload']) IF.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.