Click here to Skip to main content
15,867,594 members
Home / Discussions / Web Development
   

Web Development

 
QuestionHosting Question Pin
Kevin Marois21-Nov-22 6:41
professionalKevin Marois21-Nov-22 6:41 
AnswerRe: Hosting Question Pin
Richard Deeming21-Nov-22 21:55
mveRichard Deeming21-Nov-22 21:55 
GeneralRe: Hosting Question Pin
Kevin Marois24-Nov-22 7:26
professionalKevin Marois24-Nov-22 7:26 
GeneralRe: Hosting Question Pin
Richard Deeming24-Nov-22 21:43
mveRichard Deeming24-Nov-22 21:43 
GeneralRe: Hosting Question Pin
Kevin Marois29-Nov-22 17:11
professionalKevin Marois29-Nov-22 17:11 
QuestionJavascript Pin
Yuvraj Singh Nov202216-Nov-22 21:40
Yuvraj Singh Nov202216-Nov-22 21:40 
AnswerRe: Javascript Pin
Richard Deeming16-Nov-22 23:24
mveRichard Deeming16-Nov-22 23:24 
AnswerRe: Javascript Pin
Sam Hobbs18-Nov-22 11:59
Sam Hobbs18-Nov-22 11:59 
JokeRe: Javascript Pin
Richard Deeming20-Nov-22 22:38
mveRichard Deeming20-Nov-22 22:38 
JokeRe: Javascript Pin
Jeremy Falcon15-Dec-22 12:50
professionalJeremy Falcon15-Dec-22 12:50 
AnswerRe: Javascript Pin
Jeremy Falcon15-Dec-22 12:51
professionalJeremy Falcon15-Dec-22 12:51 
QuestionNeed a simple *everything centered* html template Pin
Member 149874928-Nov-22 16:15
Member 149874928-Nov-22 16:15 
AnswerRe: Need a simple *everything centered* html template Pin
Richard Deeming8-Nov-22 21:44
mveRichard Deeming8-Nov-22 21:44 
GeneralRe: Need a simple *everything centered* html template Pin
Member 1498749210-Nov-22 17:25
Member 1498749210-Nov-22 17:25 
GeneralRe: Need a simple *everything centered* html template Pin
Richard Deeming14-Nov-22 22:32
mveRichard Deeming14-Nov-22 22:32 
GeneralRe: Need a simple *everything centered* html template Pin
Member 1498749216-Nov-22 8:13
Member 1498749216-Nov-22 8:13 
GeneralRe: Need a simple *everything centered* html template Pin
Richard Deeming16-Nov-22 21:26
mveRichard Deeming16-Nov-22 21:26 
AnswerRe: Need a simple *everything centered* html template Pin
Jeremy Falcon15-Dec-22 13:00
professionalJeremy Falcon15-Dec-22 13:00 
QuestionFirefox won't let me change my privacy and security options. Pin
Member 1579676025-Oct-22 3:31
Member 1579676025-Oct-22 3:31 
QuestionFile upload not working, can't figure out why... Pin
DSB Audio (David Sweeney-Bear)22-Oct-22 12:34
DSB Audio (David Sweeney-Bear)22-Oct-22 12:34 
Hi all, first attempt to set up a file upload on web page.

Pretty basic stuff, but my first try so can't see why it isn't working.

Firstly I'm running on apache2 on a VPS debian 10 install.
/etc/php/7.4/apache2/php.ini contains the following:
;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
; <a href="http://php.net/file-uploads">http://php.net/file-uploads</a>
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; <a href="http://php.net/upload-tmp-dir">http://php.net/upload-tmp-dir</a>
;upload_tmp_dir =

; Maximum allowed size for uploaded files.
; <a href="http://php.net/upload-max-filesize">http://php.net/upload-max-filesize</a>
upload_max_filesize = 2M

; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20

index.html looks like this:
<!DOCTYPE html>
<html>
<body>

<form action="upload.php" method="post" enctype="multipart/form-data">
  Select image to upload:
  <input type="file" name="fileToUpload" id="fileToUpload">
  <input type="submit" value="Upload Image" name="submit">
</form>

</body>
</html>

upload.php as follows:
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));

// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
  $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  if($check !== false) {
    echo "File is an image - " . $check["mime"] . ".";
    $uploadOk = 1;
  } else {
    echo "File is not an image.";
    $uploadOk = 0;
  }
}

// Check if file already exists
if (file_exists($target_file)) {
  echo "Sorry, file already exists.";
  $uploadOk = 0;
}

// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
  echo "Sorry, your file is too large.";
  $uploadOk = 0;
}

// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
  echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
  $uploadOk = 0;
}

// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
  echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
  if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
    echo "The file ". htmlspecialchars( basename( $_FILES["fileToUpload"]["name"])). " has been uploaded.";
  } else {
    echo "Sorry, there was an error uploading your file.";
  }
}
?>

Finally, there is a folder named uploads in the path where the index.html and upload.php files reside.

When I test with a jpeg file (286k in size), I get "sorry there was an error uploading your file".

Any advice would be much appreciated, thanks.
AnswerRe: File upload not working, can't figure out why... Pin
DSB Audio (David Sweeney-Bear)22-Oct-22 12:43
DSB Audio (David Sweeney-Bear)22-Oct-22 12:43 
GeneralRe: File upload not working, can't figure out why... Pin
Richard Deeming23-Oct-22 21:52
mveRichard Deeming23-Oct-22 21:52 
GeneralRe: File upload not working, can't figure out why... Pin
Jeremy Falcon15-Dec-22 13:05
professionalJeremy Falcon15-Dec-22 13:05 
QuestionIs it possible to store a value out of fetch API for use after page reload? Pin
DSB Audio (David Sweeney-Bear)4-Oct-22 9:23
DSB Audio (David Sweeney-Bear)4-Oct-22 9:23 
AnswerRe: Is it possible to store a value out of fetch API for use after page reload? Pin
Richard Deeming4-Oct-22 21:29
mveRichard Deeming4-Oct-22 21:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.