TimUSA Posted December 30, 2007 Share Posted December 30, 2007 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/83679-image-up-load-tutorial/ Share on other sites More sharing options...
cooldude832 Posted December 30, 2007 Share Posted December 30, 2007 what do u see? Quote Link to comment https://forums.phpfreaks.com/topic/83679-image-up-load-tutorial/#findComment-425723 Share on other sites More sharing options...
redarrow Posted December 30, 2007 Share Posted December 30, 2007 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>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/83679-image-up-load-tutorial/#findComment-425724 Share on other sites More sharing options...
redarrow Posted December 30, 2007 Share Posted December 30, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/83679-image-up-load-tutorial/#findComment-425726 Share on other sites More sharing options...
TimUSA Posted December 30, 2007 Author Share Posted December 30, 2007 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/83679-image-up-load-tutorial/#findComment-425733 Share on other sites More sharing options...
redarrow Posted December 30, 2007 Share Posted December 30, 2007 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'].""; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/83679-image-up-load-tutorial/#findComment-425737 Share on other sites More sharing options...
TimUSA Posted December 30, 2007 Author Share Posted December 30, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/83679-image-up-load-tutorial/#findComment-425742 Share on other sites More sharing options...
cooldude832 Posted December 30, 2007 Share Posted December 30, 2007 are u reporting errors Quote Link to comment https://forums.phpfreaks.com/topic/83679-image-up-load-tutorial/#findComment-425751 Share on other sites More sharing options...
redarrow Posted December 30, 2007 Share Posted December 30, 2007 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'].""; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/83679-image-up-load-tutorial/#findComment-425759 Share on other sites More sharing options...
redarrow Posted December 30, 2007 Share Posted December 30, 2007 all u needed to do is add name='submit' to the form m8 but i changed it to below code......... please next time look Quote Link to comment https://forums.phpfreaks.com/topic/83679-image-up-load-tutorial/#findComment-425761 Share on other sites More sharing options...
Malevolence Posted December 30, 2007 Share Posted December 30, 2007 I know this has been solved but it's ON-Topic. How would you go about making a Browse button? . EDIT: OH RIGHT, the type=file bit distinguishes it as a Browse Button. Quote Link to comment https://forums.phpfreaks.com/topic/83679-image-up-load-tutorial/#findComment-425763 Share on other sites More sharing options...
redarrow Posted December 30, 2007 Share Posted December 30, 2007 exsplain more m8..... Quote Link to comment https://forums.phpfreaks.com/topic/83679-image-up-load-tutorial/#findComment-425765 Share on other sites More sharing options...
TimUSA Posted December 30, 2007 Author Share Posted December 30, 2007 actually the code you originally posted fixing my initial post worked. so my problem was solved. I could get the second block of code to work at all. maybe its because i am running it inside TinyPortal / SMF??? Quote Link to comment https://forums.phpfreaks.com/topic/83679-image-up-load-tutorial/#findComment-425772 Share on other sites More sharing options...
Malevolence Posted December 30, 2007 Share Posted December 30, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/83679-image-up-load-tutorial/#findComment-425781 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.