Jump to content

[SOLVED] help with uploading script


dandan321

Recommended Posts

Hello,

 

I am having trouble with getting my uploader script to do what I need it to do. The uploader works fine. What I am trying to do is give an option to upload or not to upload. (this way if an image is present in the database, users would have a choice to upload or not.)

 

I have two parts of code, html and php

 

Any help in this would be great!

 

 

 

 

 

HTML

 

 

 

 

<html>

<head></head>

<body>

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

<br><br>

Choose a file to upload:<br>

<input type="file" name="file"><br>

<input name="filec" type="checkbox" value="check" checked> Yes I want to upload a file<br>

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

</form>

</body>

</html>

 

 

 

 

 

 

 

PHP

 

 

 

 

 

<?php

 

if ($HTTP_POST_VARS['submit']) {

 

 

  if ($HTTP_POST_VARS['filec'] != "check") {

Header("Location: http://www.yahoo.com");

  } else {

 

 

 

  if (!is_uploaded_file($HTTP_POST_FILES['file']['tmp_name'])) {

    $error = "You did not upload a file!";

    unlink($HTTP_POST_FILES['file']['tmp_name']);

    // assign error message, remove uploaded file, redisplay form.

    Header("Location: somepage.php?error=" . $error);

  } else {

    //a file was uploaded

    $maxfilesize=20000000;

 

    if ($HTTP_POST_FILES['file']['size'] > $maxfilesize) {

      $error = "file is too large";

      unlink($HTTP_POST_FILES['file']['tmp_name']);

      // assign error message, remove uploaded file, redisplay form.

      Header("Location: somepage.php?error=" . $error);

    } else {

      if ($HTTP_POST_FILES['file']['type'] != "image/gif" AND $HTTP_POST_FILES['file']['type'] != "image/pjpeg") {

        $error = "This file type is not allowed";

Header("Location: somepage.php?error=" . $error);

        unlink($HTTP_POST_FILES['file']['tmp_name']);

        //assign error message, remove uploaded file, redisplay form.

      } else {

      //File has passed all validation, copy it to the final destination and remove the temporary file:

copy($HTTP_POST_FILES['file']['tmp_name'],"/hshome/martinar/martinarts.org/test/files/".$HTTP_POST_FILES['file']['name']);

      unlink($HTTP_POST_FILES['file']['tmp_name']);

      //print "File has been successfully uploaded!";

      Header("Location: somepage.php?file=" . $HTTP_POST_FILES['file']['name'] . "&type=" . $HTTP_POST_FILES['file']['type']);

      exit;

    }

    }

  }

 

  }

 

}

?>

 

Link to comment
Share on other sites

Just as a sugestion until someone who knows what they are doing can answer, I would like point out that the file starts to upload when you submit.  Perhaps if the EU doesn't want to upload a picture hide that file input using JS or on the second script maybe set the file size to 2bytes or something.

 

(Sorry if i didn't understand the problem)

Link to comment
Share on other sites

Thanks for the reply,

 

Though the problem I am having is that when the page is submitted its not reading the conditional code. If they check yes I want to upload, it should upload and if they uncheck it, the conditional code should take them to another page bypassing the upload. I want to see if my code is right.

 

Dan

Link to comment
Share on other sites

I figured it out. I am new to php. every time I was putting in = it was bypassing the if statement. What I needed to put in was == This script works but its backwords because its using non equal to != I put the != in right before I submitted the post.

 

Dan

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.