Hey guys, I need a short PHP script that can upload images into my website. The script would be in /admin/ but I need the files to go into /dog-pictures/ so can anybody help me make a script that can upload the images into the folder, as simple as that. Thanks if so!
make a new .php page write this <form action="" method="POST" enctype="multipart/form-data"> File <input type="file" name="pic"> <input type="submit" name="sb" id="sb" value="upload"> </form> <?php if(isset($_POST['sb'])) { $path = "../dog-pictures "; $file = $_FILES['pic']['tmp_name']; $newpath = "$path/$file"; move_uploaded_file($_FILES['pic']['tmp_name'], $path); } ?
this code is missing to check the file weather it is image or not .. what if some one upload php script and hack your site ???
he says he will use in admin area ! why he as admin will want to hack his own site. also it's a quickie script
Yeh, thanks guys, just one more question, in my admin bit, I also have a bit where I can edit a text file that I can update all the variables iin ti for my dog pictures, but when it is in the text box, it only shows the first line... how can I fix this, here is the code I have: <?php if (isset($_POST['submit'])) { $myFile = "*my file, private*"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = stripslashes($_POST['sf']); fwrite($fh, $stringData); fclose($fh); header('Location: index.php?a=done'); } ?> <HTML> <body> <form action="" method="post"> <textarea name="sf" cols="80" rows="10"> <?php $myFile = "*my file, private*"; $fh = fopen($myFile, 'r'); $theData = fgets($fh); fclose($fh); echo $theData; ?></textarea> <br /> <input type="submit" name="submit" value="Edit" /> </form> <?php if ($_GET['a'] == 'done') { echo 'The file was saved and now it says:<br /><br />'; $myFile = "*my file, private*"; $fh = fopen($myFile, 'r'); $theData = fgets($fh); fclose($fh); echo $theData; } ?> </body> Code (markup): The file I want to edit is a text file and it is like this, but not the actual thing lol, <?php if ($name == "name1") $nameR = "Name One"; else $nameR = "Not Found"; ?> Code (markup): But all it shows in the text box is <?php and I can't seem to fix it, any help? Thanks
<form action="" method="POST" enctype="multipart/form-data"> File <input type="file" name="pic"> <input type="submit" name="sb" id="sb" value="upload"> </form> <?php if(isset($_POST['sb'])) { $file = $_FILES['pic']['tmp_name']; $newpath = "$file"; move_uploaded_file($_FILES['pic']['tmp_name'], $path); echo $file; } ?> Code (markup):
Also make sure that the script also have security option like user login authorization so that no one can access the script except u
Yeh, thanks guys, got my whole admin area sorted out for me now Wayyy easier than editing each text file and uploading pics myself lol, thanks!