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
https://forums.phpfreaks.com/topic/45354-help-need-to-upload-a-file/
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.