Jump to content
Larry Ullman's Book Forums

Chapter 11: Handling File Uploads


Recommended Posts

Why can I not download image files the end with .JPG? Is there a way to change that? I have many images that end with .JPG.

 

 

$page_title = 'Upload images';

include($_SERVER["DOCUMENT_ROOT"]."/login/includes/header_upload_image.html");

 

$message = array();

 

if($_SERVER['REQUEST_METHOD'] == 'POST'){

 

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

 

$allowed = array('image/pjpeg', 'image/jpeg', 'image/JPG', 'image/jpg', 'image/X-PNG', 'image/PNG', 'image/png', 'image/x-png');

 

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

 

if(move_uploaded_file($_FILES['upload']['tmp_name'], $_SERVER['DOCUMENT_ROOT']."/login/uploads/{$_FILES['upload']['name']}")){

$message[0] = '<p><em> The file has been uploaded!</em></p>';

}

 

}

else{

$message[1] = '<p>Please upload a JPEG or PNG image.</p>';

}

}

 

if(file_exists($_FILES['upload']['tmp_name']) && is_file($_FILES['upload']['tmp_name'])){

 

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

}

 

}

 

ini_set("display_errors", 1);

 

?>

 

<div id="header">

 

<div id="greeting">

<?php echo '<p>Hello, '.$_SESSION['first_name'].'!</p>'; ?>

</div>

 

<a id="view_images" href="http://funwithlola.com/modification_page.php">View Images</a>

 

 

<a id="logout" href="logout.php">Logout</a>

 

 

</div>

 

 

<div id="middle">

 

 

<div id="upload">

 

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

 

<input type="hidden" name="MAX_FILE_SIZE" value="524288" />

 

<fieldset>

 

<legend>Select a JPEG or PNG image of 512mb or smaller to be uploaded:</legend>

 

<p><b>File:</b>

<input type="file" name="upload" /></p>

 

<?php if(isset($message)) echo $message[0].$message[1]; ?>

 

</fieldset>

 

<div align="center">

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

</div>

 

</div>

 

</div>

 

</form>

 

</body>

</html>

Link to comment
Share on other sites

 Share

×
×
  • Create New...