Jump to content

Recommended Posts

I have been working on a file upload script that will allow me to upload word documents, mp3's and PDF's into my site.

 

I have been working on the following script but my validation stataments are causing the upload procedure to fail, any help or advise would be appreciated.

 

<?php

 

require_once('includes/inc_functions.php');

$target = "../files/";

 

if(isset($_POST['Submit']))

{

//reads the name of the file the user submitted for uploading

$image=$_FILES['file']['name'];

// if it is not empty

if ($image)

{

// get the original name of the file from the clients machine

$filename = stripslashes($_FILES['file']['name']);

 

 

 

// get the extension of the file in a lower case format

$extension = getExtension($filename);

$extension = strtolower($extension);

// if it is not a known extension, we will suppose it is an error, print an error message

//and will not upload the file, otherwise we continue

if (($extension != "doc")  && ($extension != "jpg") && ($extension != "pdf"))

{

echo '<h1>Unknown extension!</h1>';

$errors=1;

}

else

{

 

}

}

  //If no errors registred, print the success message and show the thumbnail image created

if(isset($_POST['Submit']) && !$errors)

{ ?>

  <link href="css/admin.css" rel="stylesheet" type="text/css" />

 

  <script type="text/javascript">

function sendImg(img) {

    opener.document.add.image.value = img;

    window.close();

}

 

</script>

 

 

<h1>Thumbnail created Successfully!</h1>

<img class="hand" onClick="sendImg('<?= $image_name ?>');" src="<?= $thumb_name ?>" alt="Thumnail">

 

 

<? }

else {

?>

 

<img src="../People/JunF.jpg"

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Untitled Document</title>

</head>

 

<body>

 

  <form name="newad" method="post" enctype="multipart/form-data"  action="">

<table width="300" align="center" id="uploadImg">

<tr>

  <td colspan="2"><h1>Upload Files</h1></td>

  </tr>

<tr>

  <td colspan="2"> <p align="center" style="font-size:10px;">You can upload files with the <strong>.MP3</strong> extension using this form. Please make sure that all your MP3's have been ID3 tags or they will not display in the flash player.</p></td>

  </tr>

<tr>

  <td>Please choose a file :</td>

  <td><input name="file" type="file" /></td>

</tr>

<tr>

<td colspan="2"><div align="center">

  <input type="submit" value="Upload File"  name="Submit" />

</div></td>

</tr>

<tr>

  <td colspan="2"><div align="center"><a href="javascript:window.close()" title="Close Window">Close Window</a></div></td>

</tr>

</table>

 

</form>

</div>

 

</body>

</html><?

} // end else

?>

 

If you go to this page, http://www.recommendedcosmetics.com/admin/files2.php you will see I am getting an error with unexpected $end.

 

Link to comment
https://forums.phpfreaks.com/topic/68566-help-with-file-upload-script/
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.