Jump to content

Image up load tutorial


TimUSA

Recommended Posts

I followed it but not sure i have it right, because when i upload a file i dont see it and i dont see the upload info:

echo'
<form name="form1" method="post" action="" enctype="multipart/form-data">
<input type="file" name="imagefile">
<br>
<input type="submit" name="Submit" value="Submit">';

if(isset( $Submit ))
{
//If the Submitbutton was pressed do:

if ($_FILES['imagefile']['type'] == "image/png"){
    copy ($_FILES['imagefile']['tmp_name'], "tp-images/Image/".$_FILES['imagefile']['name']) 
    or die ("Could not copy");
        echo ""; 
        echo "Name: ".$_FILES['imagefile']['name'].""; 
        echo "Size: ".$_FILES['imagefile']['size'].""; 
        echo "Type: ".$_FILES['imagefile']['type'].""; 
        echo "Copy Done...."; 
        }
else {
            echo "<br><br>";
            echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>";
        }
}
echo'
</form>';

Link to comment
https://forums.phpfreaks.com/topic/83679-image-up-load-tutorial/
Share on other sites

trie now mate.

 

<?php

echo'
<form name="form1" method="post" action="" enctype="multipart/form-data">
<input type="file" name="imagefile">
<br>
<input type="submit" name="Submit" value="Submit">';

if(isset($_POST['Submit'] ))
{
//If the Submitbutton was pressed do:

if ($_FILES['imagefile']['type'] == "image/png"){
    copy ($_FILES['imagefile']['tmp_name'], "tp-images/Image/".$_FILES['imagefile']['name']) 
    or die ("Could not copy");
        echo ""; 
        echo "Name: ".$_FILES['imagefile']['name'].""; 
        echo "Size: ".$_FILES['imagefile']['size'].""; 
        echo "Type: ".$_FILES['imagefile']['type'].""; 
        echo "Copy Done...."; 
        }
else {
            echo "<br><br>";
            echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>";
        }
}
echo'
</form>';
?>

 

correct uploading format

<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "Possible file upload attack!\n";
}

echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";

?>

 

 

correct form format

<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="__URL__" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>

ok, your send post worked (the file uploaded ok). however before even uploading a file when i go to display the form it tells me:

Possible file upload attack!

Here is some more debugging info:Array ( )

 

and when i submit, it goes to a blank page.

 

here is my complete code now:

echo'
<form enctype="multipart/form-data" action="__URL__" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>';

$uploaddir = '/tp-images/Image/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "Possible file upload attack!\n";
}
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";

try this was in debug mode

 

corrected ok

<?php
echo'
<form enctype="multipart/form-data" action="__URL__" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="3000000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input name="submit" type="submit" value="Send File" />
</form>';

$uploaddir = '/tp-images/Image/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
if(isset($_POST['submit'])){
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "file was not upload ".$_FILES['userfile']['name']."";
}
}
?>

echo'
<form enctype="multipart/form-data" action="__URL__" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="3000000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>';

$uploaddir = '/tp-images/Image/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
if(isset($_POST['submit'])){
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "file was not upload ".$_FILES['userfile']['name']."";
}
}

 

not uploading anything, and not echoing anything :(

try now

<?php
echo'
<form enctype="multipart/form-data" action="__URL__" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="3000000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>';

$uploaddir = '/tp-images/Image/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "file was not upload ".$_FILES['userfile']['name']."";
}

?>

Well what I wanted was to have a Form (I'm on about my post) with loads of different inputs and then a file upload for images.

 

Say I have this:

 

<FORM ENCTYPE="multipart/form-data" NAME=MyForm ACTION=submit.php METHOD="POST">

Choose File

<INPUT NAME="MyFile" TYPE="File">

<INPUT NAME="submit" VALUE="Submit" TYPE="submit">

</FORM>

 

The TYPE="File" bit deciphers that it is a [textbox] [browsebutton] layout. Right?

 

RedArrow? Could YOU reply and help me with my other post?

(http://www.phpfreaks.com/forums/index.php/topic,174788.0.html)

 

I'm really stuck on it.

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.