Jump to content

HELP! need to upload a file


lisawebs

Recommended Posts

Hi, I'm using this to upload a file

but doesnt work,

the php part simply do nothing.

 

 

PAGE 1

<html><body>

<form enctype="multipart/form-data" action="http://www.usa21.net/testupload.php" method="POST">

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

Send this file: <input name="userfile" type="file">

<input type="submit" value="send file">

</form></body></html>

 

 

PAGE 2 php

<html><body>this is the php<br>

<?php

$uploaddir = '';

$uploadfile = $uploaddir. $_FILES['userfile']['name'];

print "<pre>";

if ($_FILES['userfile']['size'] > 80000)

    print "file too big";

else if ($_FILES['userfile']['type'] != "image/jpg)

  print "file isnt a JPG format"

else if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $_FILES['userfile']['name'])) {

    print "file was uploaded:\n";

    print_r($_FILES);

} else {

    print "unable to complete operation:\n";

    print_r($_FILES);

}

print "</pre>";

?>

</body></html>

Link to comment
Share on other sites

<?php
$path = "";
if (!isset($HTTP_POST_FILES['userfile'])){ echo "
<FORM ENCTYPE=multipart/form-data ACTION=?page=Upload METHOD=POST>
<p>The file:<br>
<INPUT TYPE=file NAME=userfile><br />
<INPUT TYPE=submit VALUE=Upload>
</p>
</FORM>
"; }else{
if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {
if (($HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/png")) {
if (file_exists($path . $HTTP_POST_FILES['userfile']['name'])) { echo "The file already exists, try calling your file a different name.<br>"; }else{
$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path .
$HTTP_POST_FILES['userfile']['name']);
if (!$res) { echo "upload failed!<br>"; exit; } else { echo "upload sucessful<br><br>"; }
echo "File Name: ".$HTTP_POST_FILES['userfile']['name']."<br>";
echo "File Path: <a href=uploads/".$HTTP_POST_FILES['userfile']['name']." TARGET=_BLANK>uploads/".$HTTP_POST_FILES['userfile']['name']."</a><br>";
echo "File Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>";
echo "File Type: ".$HTTP_POST_FILES['userfile']['type']."<br>";
echo "<img src=uploads/".$HTTP_POST_FILES['userfile']['name']."><br>";
}}}}
?>

 

hasent been tested! ive put some extra file types in there aswell

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.