PHP - Php Uploader Script Need Help
Ok this script works but it needs to do more.
I need to resize the images that get uploaded to 300px to 300px because the images are way to big and then i need to add a if statement to send back to flash if the file is to small to upload so it will look best. so no file that is less then 300px by 300px can be uploaded. this script is doing two things One it uploads the picture to some username folder Two it inserts into the database where username. <?php include "../php/connect.php"; $username = $_POST['username']; $username = stripslashes($username); $username = mysql_real_escape_string($username); if(@!empty($_FILES)) { $_FILES['Filedata']['name'] = Relocate(utf8_decode($_FILES['Filedata']['name']),$username); $filepath = getcwd()."/".$_GET['dir']."/"; if(!file_exists($filepath)) mkdir($filepath,0777); chmod($filepath,0777); if(move_uploaded_file($_FILES['Filedata']['tmp_name'], $filepath . $_FILES['Filedata']['name'])) chmod($filepath.$_FILES['Filedata']['name'], 0777); } function Relocate($str,$username) { $filename = "UserPhoto.jpg";//md5($str); $setavatar = mysql_query("UPDATE accounts SET avatar = 'http://wiistream.net/users/$username/images/$filename' WHERE username = '$username'"); echo '&msgText=' . $username . ''; return $filename; } Relocate($str,$username); ?> Similar TutorialsHey guys I've made a php uploader, <form enctype="multipart/form-data" action="upload.php" method="POST"> Please choose a file: <input name="uploaded" type="file" /><br /> <input type="hidden" name="sent"/> <input type="submit" value="Upload" /> <?php /** * @author Jragon * @copyright 2010 */ function stringrand() { for ($i = 0; $i < 6; $i++) { switch (rand(1, 3)) { case 1: $rand .= chr(rand(48, 57)); break; //0-9 case 2: $rand .= chr(rand(65, 90)); break; //A-Z case 3: $rand .= chr(rand(97, 122)); break; //a-z } } return $rand; } if (isset($_POST['sent'])) { switch ($_FILES['uploaded']['name']) { case 'image/jpeg': $type = 'image'; $ext = 'jpg'; break; case 'image/gif': $type = 'image'; $ext = 'gif'; break; case 'image/png': $type = 'image'; $ext = 'png'; break; case 'video/mp4': $type = 'video'; $type = 'mp4'; break; case 'application/x-shockwave-flash': $type = 'video'; $ext = 'flv'; break; case 'audio/mp3': $type = 'audio'; $ext = 'mp3'; break; default: $type = ''; break; } if ($type == 'video') { $name = basename($_FILES['uploaded']['name']); $target = "/upload/$type/"; $target = $target . stringradnd() . ".$ext"; $worked = false; if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file " . $name . " has been uploaded"; $worked = true; } else { echo "Sorry, there was a problem uploading your file."; } } elseif ($type == 'audio') { $name = basename($_FILES['uploaded']['name']); $target = "/upload/$type/"; $target = $target . stringradnd() . ".$ext"; $worked = false; if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file " . $name . " has been uploaded"; $worked = true; $target = $target . "&plugins=revolt-1"; } else { echo "Sorry, there was a problem uploading your file."; } } elseif ($type == 'image') { $name = basename($_FILES['uploaded']['name']); $target = "/upload/$type/"; $target = $target . stringradnd() . ".$ext"; $worked = false; if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file " . $name . " has been uploaded"; $worked = true; } else { echo "Sorry, there was a problem uploading your file."; } } elseif ($type == '') { $worked = false; echo "Sorry the only extensions you can use a jpeg jpg gif png mp3 mp4 flv"; } if ($worked == true) { echo <<< ENDHTML <script type='text/javascript' src='/flvplayer/swfobject.js'></script> <div id='mediaspace'>This text will be replaced</div> <script type='text/javascript'> var so = new SWFObject('/flvplayer/player.swf','mpl','470','320','9'); so.addParam('allowfullscreen','true'); so.addParam('allowscriptaccess','always'); so.addParam('wmode','opaque'); so.addVariable('file','/upload/{$name}'); so.write('mediaspace'); </script> ENDHTML; } } ?> But its not working, it dosent upload the files Please help Jragon i am build am url image uploader he only problem i am having is take the url form the forum and placeing it in this code $content = file_get_contents('$img '); file_put_contents('/home/sambobi/public_html/bob/b_images/$id.jpg', $content); the variable $img is the url variable and the $id is random numbers and letter but both parts of this wont works can any one help This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=348113.0 Does anyone have an image up-loader script that is easy to manipulate for the address, and renaming based upon the number in the file system the image is, or do I need to work on figuring it out on my own? Hi there I've been wanting to make a decent image uploader for a long time now. Here are the things that need to be able to be done: Select a whole folder of images, or a selection Each image must be rescaled twice, and every scaling must be renamed and put inside a seperate folder The new name of the image must be put in a database, and also the extension of the image And that's pretty much it... Ofcourse the biggest problem is the first one, since it cannot be done in PHP solely but it needs some javascript/ajax? I've never really worked with any plugins or so so I'm quite new to this, does anyone have a very easy one that I can easily adjust? Thanks in advance Trying to have my image uploader transfer up SWF files without any luck. It uploads the file name correctly but is not transferring the file itself to the file directory. It works fine with my regular images but just not with the SWF files. I've changed all occurences of JPG and replaced them with SWF. Help? Perhaps I'm missing something? Thanks for your help! Code: [Select] <?php $item_image = $_FILES['image_upload_box']['name']; $item_id = $_GET['id']; $sql="UPDATE imagetable SET sp_image='$item_image' WHERE id = '$item_id'"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } else { // upload the file if ((isset($_POST["submitted_form"])) && ($_POST["submitted_form"] == "image_upload_form")) { // file needs to be jpg,gif,bmp,x-png and 4 MB max if (($_FILES["image_upload_box"]["type"] == "image/swf" || $_FILES["image_upload_box"]["type"] == "image/pjpeg" || $_FILES["image_upload_box"]["type"] == "image/gif" || $_FILES["image_upload_box"]["type"] == "image/x-png") && ($_FILES["image_upload_box"]["size"] < 400000000)) { // some settings $max_upload_width = 800; $max_upload_height = 300; // if user chosed properly then scale down the image according to user preferances if(isset($_REQUEST['max_width_box']) and $_REQUEST['max_width_box']!='' and $_REQUEST['max_width_box']<=$max_upload_width){ $max_upload_width = $_REQUEST['max_width_box']; } if(isset($_REQUEST['max_height_box']) and $_REQUEST['max_height_box']!='' and $_REQUEST['max_height_box']<=$max_upload_height){ $max_upload_height = $_REQUEST['max_height_box']; } // if uploaded image was JPG/JPEG if($_FILES["image_upload_box"]["type"] == "image/swf" || $_FILES["image_upload_box"]["type"] == "image/swf"){ $image_source = imagecreatefromswf($_FILES["image_upload_box"]["name"]); } // if uploaded image was GIF if($_FILES["image_upload_box"]["type"] == "image/gif"){ $image_source = imagecreatefromgif($_FILES["image_upload_box"]["name"]); } // BMP doesn't seem to be supported so remove it form above image type test (reject bmps) // if uploaded image was BMP if($_FILES["image_upload_box"]["type"] == "image/bmp"){ $image_source = imagecreatefromwbmp($_FILES["image_upload_box"]["name"]); } // if uploaded image was PNG if($_FILES["image_upload_box"]["type"] == "image/x-png"){ $image_source = imagecreatefrompng($_FILES["image_upload_box"]["name"]); } $remote_file = "image_files/".$_FILES["image_upload_box"]["name"]; imagejpeg($image_source,$remote_file,100); chmod($remote_file,0644); // get width and height of original image list($image_width, $image_height) = getimagesize($remote_file); if($image_width>$max_upload_width || $image_height >$max_upload_height){ $proportions = $image_width/$image_height; if($image_width>$image_height){ $new_width = $max_upload_width; $new_height = round($max_upload_width/$proportions); } else{ $new_height = $max_upload_height; $new_width = round($max_upload_height*$proportions); } $new_image = imagecreatetruecolor($new_width , $new_height); $image_source = imagecreatefromswf($remote_file); imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height); imagejpeg($new_image,$remote_file,100); imagedestroy($new_image); } imagedestroy($image_source); MOD EDIT: [code] . . . [/code] BBCode tags added. Hi I have this script which I hope to upload an image to my images folder and put the name of the image in my database along with what category it belongs too. I keep getting this error though.... Access denied for user 'websitename.co.uk'@'localhost' (using password: NO) Now when I check the server logs I get the following error to go with it... [Thu Dec 23 13:53:30 2010] [error] [client 0.0.0.0] PHP Warning: mysql_query() [<a href='function.mysql-query'>function.mysql-query</a>]: A link to the server could not be established in /home/sites/website name.co.uk/public_html/manage/upload.php on line 14, referer: http://www.websitename.co.uk/manage/add_image.php?cat='Robbers' Lie 14 is this... mysql_query("INSERT INTO `polaroids` VALUES ('$pic', '$category')") or die (mysql_error()); Ok so here is the code from the beginning. Ill start with the form its self.... <form enctype="multipart/form-data" action="upload.php" id="polaroidfrm" method="POST"> Please upload a PNG for the category <?php echo $_GET['cat']; ?>:<br> <input name="photo" type="file" size="40"/> </p> <br/> <input type="hidden" name="category" Value="<?php echo $_GET['cat']; ?>"> <input type="submit" value="Submit" name="insert_polaroid"> </form> then the upload page.... <?php //This is the directory where images will be saved $target = "images/polaroids/"; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $category=$_POST['catid']; $pic=($_FILES['photo']['name']); // Connects to your Database include('../../Connections/photoconnect.php'); session_start(); //Writes the information to the database mysql_query("INSERT INTO `polaroids` VALUES ('$pic', '$category')") or die (mysql_error()); //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok $success = "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; $url = "polaroids.php?polaroidpass='".$success."'" or die(mysql_error()); header("Location: ".$url.""); } else { //Gives and error if its not $fail = "Sorry, there was a problem uploading your file."; $url = "polaroids.php?polaroidfail='".$fail."'" or die(mysql_error()); header("Location: ".$url.""); } ?> All I want to do is upload an image to my images folder, which is on the site root, so mysite.com/images here is my code: Code: [Select] <form action="uploadimage.php" method="post" enctype="multipart/form-data" name="form1" id="form1"> <p> <label>Choose image to upload <input type="file" name="image" id="image" /> </label> </p> <p> <label> <input type="submit" name="imageupload" id="imageupload" value="Upload Image" /> </label> </p> </form> <?php $imagename = "1testimage"; if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png"))) move_uploaded_file ($_FILES["file"]["tmp_name"],"images/" . $imagename.".gif"); ?> Cn anyone see why this is not working/ I have chenged the permissions on my hosting account to read and write... Ok , so im fairly new to this beeen watching tuts , messing around with coding to see what does what , well i cant seem to get this uploader to send a image to the db it just errors the code is <html> <head> <title>Image Uploader</title> </head> <body> <form method="post" action="index.php" enctype="multipart/form=data"> File: <input type="file" name="image" /> <input type="submit" value="upload" /> </form> <?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); //file propities $file = $_FILES['image']['tmp_name']; if (!isset($file)) { echo "Please select an image"; } else { $image = file_get_contents ($_FILES['image']['tmp_name']); $image_name = $_FILES['image']['name']; $image_size = getimagesize($_FILES['image']['tmp_name']); if ($image_size==FALSE) echo "This is not an image file"; else { if (!$insert = mysql_query("INSERT INTO imagedb VALUES ('','$image_name','$image')")) echo "problem uploading image"; else { $lastid = mysql_insert_id(); echo "image uploaded<p>Your image</p><img scr =get.php?id=$lastid>"; } } } ?> </body> </html> thats my index.php then my get.php is <?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); $id = addslashes($_REQUEST['id']); $image = mysql_query("SELECT * FROM imagedb WHERE id=$id"); $image = mysql_fetch_assoc($image); $image = $image['image']; header("Content-type: img/jpeg"); echo $image; ?> My database is called 'test' and my table is called 'imagedb' and i have 3 fields 'id'name'image. help would be much appriciated thankyouu hello all, i have a photo uploader that clients use. i want this to be able to put clients photos in there own folder within a specified path. $(function() { $('#custom_file_upload').uploadify({ 'uploader' : '/uploadify.swf', 'script' : 'uploadify.php?user=<?php echo("$logged[ip]"); ?>', 'cancelImg' : '/cancel.png', 'folder' : '/wuploads/{$logged('email')}', 'multi' : true, 'auto' : true, 'fileExt' : '*.ZIP;*.zip;*.rar', 'queueID' : 'custom-queue', 'queueSizeLimit' : 1000, 'simUploadLimit' : 1000, 'removeCompleted': true, 'onSelectOnce' : function(event,data) { $('#status-message').text(data.filesSelected + ' files have been added to the queue.'); }, 'onAllComplete' : function(event,data) { $('#status-message').text(data.filesUploaded + ' files uploaded, ' + data.errors + ' errors.'); } }); }); i have tried the code above with 'folder' : '/wuploads/{$logged('email')}', but this doesnt seem to work, im new to php and tried a few different combinations but it wont budge! thanks, gavin Hi. I have a piece of code that uploads an image. It works great. Ive added it to some more coding inserting information into a database. Now the code doesn't work. I have used some error reporting and i get Notice: Undefined index: newImage in /home/sites/submitpost.php on line 9 Notice: Undefined index: newImage in /home/sites/submitpost.php on line 10 Notice: Undefined index: newImage in /home/sites/submitpost.php on line 11 Notice: Undefined index: newImage in /home/sites/submitpost.php on line 12 Here is the code. Can someone explain whats wrong? include('database.php'); session_start(); //another photo uploader $fileName9 = $_FILES['newImage']['name']; $tmpName = $_FILES['newImage']['tmp_name']; $fileSize = $_FILES['newImage']['size']; $fileType = $_FILES['newImage']['type']; //$randName = md5(rand() * time()); //$fileName9 = $randName + $fileName9; $limit_size=2097152; $folder = "{$_SERVER['DOCUMENT_ROOT']}/images/memberImages/"; if ($fileSize >= $limit_size){$msg1="Your uploaded file size is more than 2MB so please reduce the file size and then upload. Visit the help page to know how to reduce the file size.<BR>"; $success=0;} elseif ($fileName9=="") {$error = "Please choose a file to upload"; $success=0;} //elseif ($fileType!== 'image/jpeg' || 'image/gif' || 'image/png' || 'image/JPG') {$error = "false";} $types = array('image/jpeg', 'image/gif', 'image/png', 'image/JPG', 'image/pjpeg', 'image/x-png'); if (in_array($fileType, $types)) { if(move_uploaded_file($tmpName , $folder.$fileName9)) { $Fnew1 = $fileName9; $place=mysql_real_escape_string($_POST['place']); $cityname=mysql_real_escape_string($_POST['cityname']); $city=mysql_real_escape_string($_POST['city']); $title=mysql_real_escape_string($_POST['ComTitle']); $message=mysql_real_escape_string($_POST['commentDescrip']); $member=mysql_real_escape_string($_POST['member']); $time=time(); mysql_query("INSERT INTO posts (type, title, message,postUserID, time, cityID, status, place, image) VALUES('$type','$title','$message','$member', '$time', '$city', '1', '$place', '$Fnew1')") or die('post error'); $id = mysql_insert_id(); $url = "/view-thankyou.php?city=$cityname&type=$type#name"; header("Location: $url"); } else {echo"Move fail"; } } ?> Hi: I have written code that will allow a user to upload a file and that will allow the user to view/delete the image when clicking on the link. I'm having trouble in the table where the image information is organized - the table just duplicates information about an image into another column,.how can I fix this? Here's my code: Code: [Select] <? if ($handle = opendir('images/')) { while (false !== ($file = readdir($handle))) { $TPL['fileList'][] = array( 'fileName' => $file, 'fileSize' => filesize('images/'.$file), 'fileDate' => 'Jan 2, 2029' ); } } switch ($_REQUEST['act']): default: break; if (empty($_FILES['userfile']['name'])): $TPL['errMsg'] = "No file selected"; $TPL['dispErrMsg'] = true; break; endif; copy ($_FILES['userfile']['tmp_name'], 'images/'.$_FILES['userfile']['name']); break; case 'del': echo "delete this file? ($_GET)['userfile']['name']"; endswitch; ?> <html> <head> <title>Comp10065 - Lab 4: File Upload</title> <style type="text/css"> body {background-color:yellow} div#container {margin-right: auto; margin-left: auto; border: 1px solid #EEEEEE; width: 800px; padding: 10px; background-color:white} h1 {text-align: center; color:orange; background-color:white} table {width: 700px; margin-bottom: 15px} table th {text-align: left;padding: 0px 10 0px 10px} table td{padding: 0px 10 0px 10px; border: 1px solid #AAAAAA} tr.odd {background-color: #EEEEEE} tr.even {background-color: #CCCCCC} .message {color:red} div#debug {border: 1px solid #BBBBBB} </style> <script language="JavaScript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.js"></script> <script type="text/javascript"> function popup(img) { var day= new Date(); var windowParms = 'width=400,height=400,scrollbars,resizable'; var htmlPage = '<html><body><img src="' + img + '"><br>' + ' <form><input type="button" ' + ' onclick="javascript:window.close();" value="Close Window"><br>\n' + ' </form></body></html>\n'; var popupWindow = window.open('',day.getTime(),windowParms); popupWindow.document.write(htmlPage); popupWindow.document.close(); } </script> <script> $(function() { $("div#debug").hide(); $("a#debugLink").click(function () {$("div#debug").toggle("slowly"); }); }); </script> </head> <body > <div id="container"> <h1> Picture Uploader!</h1> <p>Click here to <a href="<?= $_SERVER['PHP_SELF'] ?>">refresh</a> this page.</p> <table> <tr> <th>File Name (<a href="upload.php?act=sortby&col=filename">sort</a>)</th> <th>Size KBytes (<a href="upload.php?act=sortby&col=size">sort</a>)</th> <th>Date</th> </tr> </td> <? foreach($TPL['fileList'] as $key => $val): ?> <td><a href="<?= 'images/'.$val['fileName'] ?>"><?=$val['fileName'] ?></a></td> <td><?= $val['fileName'] ?></td> <td><?= $val['fileSize'] ?></td> <td><?= $val['fileDate'] ?></td> <td><a href="#" onClick="popup('images/uieiuirdi.jpg')" >View</a></td> <td align=center><a href=upload.php?act=del&file=uieiuirdi.jpg>Delete</a></td> </tr> <? endforeach ?> </table> <p class="message">Records sorted by size</p> <form action=upload.php method="post" enctype='multipart/form-data'> <input type="hidden" name="MAX_FILE_SIZE" value="2000000"> <input type="hidden" name="act" value="post"> <input type="file" name="userfile" size="60" value=""> <br> <input type="submit" value="UPLOAD FILE" name="submit">Do not upload large files! </form> <? if($TPL['dispErrMsg']): ?> <p><?= $TPL['errMsg'] ?></p> <? endif; ?> <hr> <p>Click <a href="#" id = "debugLink"> here </a> for debug info. Jquery show/hide effect.</p> <div id="debug"> <p>This debug info is here to help you. You are only required to display the $_POST and $_FILES array</p> <pre > <? print_r($TPL) ?></pre> </div> </div> </body> </html> I am using CKeditor 3.2. Everything is going fine except image uploader, flash uploader and table... These content are not working.. my site is in PHP.. I have searched too much to solution on Google not found a right answer... infact, there are many results talking about filemanager folder which i was not able to find on downloaded zip. One more thing; when i am uploading images through default uploader and send it to database everything is fine, but when i am retrieving that image on some page; the image is not displaying, /"/" kind of code displaying instead of the images.... What to do to resolve this issue..... Kindly help me its very needed... Thanks in advance.... I Need help Integrating An Video Upload System Into The Mybb Forum Software. I understand You Need ffmeg +jwplayer ive already installed that on my server.But Now I Need A Little Help Integrating And Uploader Into The Software, So It Can Post The Video Into An Thred When My Users Upload. This has probably been asked here tons of times, and yes I've searched on google but I can't find a decently explained method. What I want is to be able to upload a whole directory of pictures at once. These pictures must go through the following: Be cropped in size (about 600px width/height) This must be stored in a folder under a random name A thumbnail must be made, with the same name, in another folder The location of each picture should be stored in a database What I've said here is all PHP I presume, and that I can take care of, I think. The problem is the multiuploader. I understand it can't be done in PHP, since PHP lets only 1 file per input tag, so you cannot select a directory. So this should be done with javascript/java/??? Additional questions: if I do mkdir('/pictures/$mapname/thumbs');, the 'pictures' already exists but the rest doesn't. Does it create the $mapname dir and the thumbs, or should I use 2 different mkdir's? What width is best to save the images to? What with is the best to save the thumbs to? So many more, but I'll keep it at this! I know it's a lot of questions, but it would really be handy if I could do this! Thanks in advance! Hi, Ive had a website for some time that allows people to upload pictures to certain directories, and each directory had its own upload script, I decided as Im slowley getting better at php to combine it all into 1 file and include it, all works great, but now I notice its a lot of repeated code as the only thing that changes for each function is the directory name, here is the script as it is: <?php // James Davies, Revised 2010 // Create the main NSFW upload function function demotivate() { //configure site specific variables $website = 'http://www.thenudedeer.com'; //what is the folder name $phpbbdir = '/demotivate/'; // Create an array containing all valid upload file types for this script $allowed_types = array( "image/gif" => "gif", "image/pjpeg" => "jpg", "image/jpg" => "jpg", "image/jpeg" => "jpg", "image/png" => "png", "image/x-png" => "png", // Add more types here if you like ); // Check to see if the file type is in the allowed types array if(!array_key_exists($_FILES['userfile']['type'], $allowed_types)) { die("Invalid file type."); } // Set the maximum uploadable file size => 512000 = 500kb $maxfilesize = 512000; // Is the file larger than it is allowed to be? if($_FILES['userfile']['size'] > $maxfilesize) { die("File too large"); } // Where will the file be uploaded to? $uploaddir = $_SERVER['DOCUMENT_ROOT'] . $phpbbdir; // What is the files temporary name? $file = $_FILES['userfile']['tmp_name']; // What is the files actual name? $filename = $_FILES['userfile']['name']; // Does this file already exist on the server? if(file_exists($uploaddir . $filename)) { //die("A file with that name already exists on this server."); die("File already existed, [img]http://" . $website . $phpbbdir . $filename ."[/img]"); } else { // This file does not already exist, so copy it. copy($file, $uploaddir.$filename) or die("Could not copy file."); } // All done! :-) echo "<br />"; echo "<font color=red><b>"; echo "Upload successful"; echo "<br />"; echo "Copy and Paste the following Code"; echo "</font><br/>"; echo "<font color='green'><b>"; echo "<br />"; echo "[img]http://" . $website . $phpbbdir . $filename; echo "[/img]"; echo "<br/>"; echo "<br/>"; echo '<img class="img" src="' .$phpbbdir .$filename.'">'; echo "<br />"; echo "<br />"; echo "</font>"; echo "<br /><br />"; } function nsfw() { //configure site specific variables $website = 'http://www.thenudedeer.com'; //what is the folder name $phpbbdir = '/nsfw/'; // Create an array containing all valid upload file types for this script $allowed_types = array( "image/gif" => "gif", "image/pjpeg" => "jpg", "image/jpg" => "jpg", "image/jpeg" => "jpg", "image/png" => "png", "image/x-png" => "png", // Add more types here if you like ); // Check to see if the file type is in the allowed types array if(!array_key_exists($_FILES['userfile']['type'], $allowed_types)) { die("Invalid file type."); } // Set the maximum uploadable file size => 512000 = 500kb $maxfilesize = 512000; // Is the file larger than it is allowed to be? if($_FILES['userfile']['size'] > $maxfilesize) { die("File too large"); } // Where will the file be uploaded to? $uploaddir = $_SERVER['DOCUMENT_ROOT'] . $phpbbdir; // What is the files temporary name? $file = $_FILES['userfile']['tmp_name']; // What is the files actual name? $filename = $_FILES['userfile']['name']; // Does this file already exist on the server? if(file_exists($uploaddir . $filename)) { //die("A file with that name already exists on this server."); die("File already existed, [img]http://" . $website . $phpbbdir . $filename ."[/img]"); } else { // This file does not already exist, so copy it. copy($file, $uploaddir.$filename) or die("Could not copy file."); } // All done! :-) echo "<br />"; echo "<font color=red><b>"; echo "Upload successful"; echo "<br />"; echo "Copy and Paste the following Code"; echo "</font><br/>"; echo "<font color='green'><b>"; echo "<br />"; echo "[img]http://" . $website . $phpbbdir . $filename; echo "[/img]"; echo "<br/>"; echo "<br/>"; echo '<img class="img" src="' .$phpbbdir .$filename.'">'; echo "<br />"; echo "<br />"; echo "</font>"; echo "<br /><br />"; } function fail() { //configure site specific variables $website = 'http://www.thenudedeer.com'; //what is the folder name $phpbbdir = '/fail/'; // Create an array containing all valid upload file types for this script $allowed_types = array( "image/gif" => "gif", "image/pjpeg" => "jpg", "image/jpg" => "jpg", "image/jpeg" => "jpg", "image/png" => "png", "image/x-png" => "png", // Add more types here if you like ); // Check to see if the file type is in the allowed types array if(!array_key_exists($_FILES['userfile']['type'], $allowed_types)) { die("Invalid file type."); } // Set the maximum uploadable file size => 512000 = 500kb $maxfilesize = 512000; // Is the file larger than it is allowed to be? if($_FILES['userfile']['size'] > $maxfilesize) { die("File too large"); } // Where will the file be uploaded to? $uploaddir = $_SERVER['DOCUMENT_ROOT'] . $phpbbdir; // What is the files temporary name? $file = $_FILES['userfile']['tmp_name']; // What is the files actual name? $filename = $_FILES['userfile']['name']; // Does this file already exist on the server? if(file_exists($uploaddir . $filename)) { //die("A file with that name already exists on this server."); die("File already existed, [img]http://" . $website . $phpbbdir . $filename ."[/img]"); } else { // This file does not already exist, so copy it. copy($file, $uploaddir.$filename) or die("Could not copy file."); } // All done! :-) echo "<br />"; echo "<font color=red><b>"; echo "Upload successful"; echo "<br />"; echo "Copy and Paste the following Code"; echo "</font><br/>"; echo "<font color='green'><b>"; echo "<br />"; echo "[img]http://" . $website . $phpbbdir . $filename; echo "[/img]"; echo "<br/>"; echo "<br/>"; echo '<img class="img" src="' .$phpbbdir .$filename.'">'; echo "<br />"; echo "<br />"; echo "</font>"; echo "<br /><br />"; } ?> there must be a way to stop repeating all the same code for each function? many thanks dear folks
this question is regarding the plugin update, file uploader and SFTP - on a wordpress that runs on secured- server
I think I know the answer to the following question as "not possible" but I figured I would check. my sites are on servers where we disable FTP access and only use SFTP access, and also on a different port (not port 22). what if i want to use a automated maintaining service like the following https://mainwp.com http://wwww.infinitewp.com automated Installing and updating plugins to the sites does not seem to work and I assume this is the reason why. I'm also assuming the File uploader extension will not work either. Can anyone confirm this for sure though? Any ideas as far as workaround? one might think of the following way: Can you try adding your SFTP settings into the wp-config of one of my sites to see if that allows the functions to work? we can see an example in http://codex.wordpre...g_wp-config.php under WordPress Upgrade Constants or possibly try this plugin SSH SFTP Updater Support do you have any idear!? cf: https://mainwp.com/f...&highlight=sftp Hi everyone! I've been working on a php script to replace links that contain a query with direct links to the files they would redirect to. Hi i have this upload script which works fine it uploads image to a specified folder and sends the the details to the database. but now i am trying to instead make a modify script which is Update set so i tried to change insert to update but didnt work can someone help me out please this my insert image script which works fine but want to change to modify instead Code: [Select] <?php mysql_connect("localhost", "root", "") or die(mysql_error()) ; mysql_select_db("upload") or die(mysql_error()) ; // my file the name of the input area on the form type is the extension of the file //echo $_FILES["myfile"]["type"]; //myfile is the name of the input area on the form $name = $_FILES["image"] ["name"]; // name of the file $type = $_FILES["image"]["type"]; //type of the file $size = $_FILES["image"]["size"]; //the size of the file $temp = $_FILES["image"]["tmp_name"];//temporary file location when click upload it temporary stores on the computer and gives it a temporary name $error =array(); // this an empty array where you can then call on all of the error messages $allowed_exts = array('jpg', 'jpeg', 'png', 'gif'); // array with the following extension name values $image_type = array('image/jpg', 'image/jpeg', 'image/png', 'image/gif'); // array with the following image type values $location = 'images/'; //location of the file or directory where the file will be stored $appendic_name = "news".$name;//this append the word [news] before the name so the image would be news[nameofimage].gif // substr counts the number of carachters and then you the specify how how many you letters you want to cut off from the beginning of the word example drivers.jpg it would cut off dri, and would display vers.jpg //echo $extension = substr($name, 3); //using both substr and strpos, strpos it will delete anything before the dot in this case it finds the dot on the $name file deletes and + 1 says read after the last letter you delete because you want to display the letters after the dot. if remove the +1 it will display .gif which what we want is just gif $extension = strtolower(substr($name, strpos ($name, '.') +1));//strlower turn the extension non capital in case extension is capital example JPG will strtolower will make jpg // another way of doing is with explode // $image_ext strtolower(end(explode('.',$name))); will explode from where you want in this case from the dot adn end will display from the end after the explode $myfile = $_POST["myfile"]; if (isset($image)) // if you choose a file name do the if bellow { // if extension is not equal to any of the variables in the array $allowed_exts error appears if(in_array($extension, $allowed_exts) === false ) { $error[] = 'Extension not allowed! gif, jpg, jpeg, png only<br />'; // if no errror read next if line } // if file type is not equal to any of the variables in array $image_type error appears if(in_array($type, $image_type) === false) { $error[] = 'Type of file not allowed! only images allowed<br />'; } // if file bigger than the number bellow error message if($size > 2097152) { $error[] = 'File size must be under 2MB!'; } // check if folder exist in the server if(!file_exists ($location)) { $error[] = 'No directory ' . $location. ' on the server Please create a folder ' .$location; } } // if no error found do the move upload function if (empty($error)){ if (move_uploaded_file($temp, $location .$appendic_name)) { // insert data into database first are the field name teh values are the variables you want to insert into those fields appendic is the new name of the image mysql_query("INSERT INTO image (myfile ,image) VALUES ('$myfile', '$appendic_name')") ; exit(); } } else { foreach ($error as $error) { echo $error; } } //echo $type; ?> I'm having trouble echoing $year in my script. Listed below is the script, just below ,$result = mysql_query("SELECT * FROM $dbname WHERE class LIKE '%$search%'") or die(mysql_error());, in the script I try to echo $year. It doesn't show up in the table on the webpage. Everything else works fine. Any help wold be appreciated greatly. Thanks in advance. <?php include 'config2.php'; $search=$_GET["search"]; // Connect to server and select database. mysql_connect($dbhost, $dbuser, $dbpass)or die("cannot connect"); mysql_select_db("vetman")or die("cannot select DB"); $result = mysql_query("SELECT * FROM $dbname WHERE class LIKE '%$search%'") or die(mysql_error()); // store the record of the "" table into $row //$current = ''; echo "<table align=center border=1>"; echo "<br>"; echo "<tr>"; echo "<td align=center>"; ?> <div style="float: center;"><a><h1><?php echo $year; ?></h1></a></div> <?php echo "</td>"; echo "</tr>"; echo "</table>"; // keeps getting the next row until there are no more to get if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 2; echo "<table align=center>"; echo "<br>"; while($row = mysql_fetch_array($result)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; echo "<td align=center>"; ?> <div style="float: left;"> <div><img src="<?php echo $image1; ?>"></div> </div> <?php echo "</td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i > 0) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; echo '</tr>'; } mysql_close(); ?> </table> |