gnawz Posted April 10, 2009 Share Posted April 10, 2009 Hi, I have an image upload script that opens a pop-up window for the user to ulpoad images... It works well with localhost but does not work on the host server. What could be the reason Link to comment https://forums.phpfreaks.com/topic/153494-image-upload-problem/ Share on other sites More sharing options...
gaza165 Posted April 10, 2009 Share Posted April 10, 2009 Show us the code and we will take a look. Link to comment https://forums.phpfreaks.com/topic/153494-image-upload-problem/#findComment-806486 Share on other sites More sharing options...
gnawz Posted April 10, 2009 Author Share Posted April 10, 2009 config.inc.php <? /* * Path to a directory which holds the images. */ $imagebasedir = '../../../../uploads'; /* * An absolute or relative URL to the image folder. * This url is used to generate the source of the image. */ $imagebaseurl = 'uploads'; /* * Allow your users to browse the subdir of the defined basedir. */ $browsedirs = true; /* * If enabled users will be able to upload * files to any viewable directory. You should really only enable * this if the area this script is in is already password protected. */ $allowuploads = true; /* * If a user uploads a file with the same * name as an existing file do you want the existing file * to be overwritten? */ $overwrite = false; /* * Define the extentions you want to show within the * directory listing. The extensions also limit the * files the user can upload to your image folders. */ $supportedextentions = array( 'gif', 'png', 'jpeg', 'jpg', 'bmp' ); /* * If you want to add your own special file icons use * this section below. Each entry relates to the extension of the * given file, in the form <extension> => <filename>. * These files must be located within the dlf directory. */ $filetypes = array ( 'png' => 'jpg.gif', 'jpeg' => 'jpg.gif', 'bmp' => 'jpg.gif', 'jpg' => 'jpg.gif', 'gif' => 'gif.gif', 'psd' => 'psd.gif', ); ?> ?> select_image.php <? require('config.inc.php'); error_reporting(0); if((substr($imagebaseurl, -1, 1)!='/') && $imagebaseurl!='') $imagebaseurl = $imagebaseurl . '/'; if((substr($imagebasedir, -1, 1)!='/') && $imagebasedir!='') $imagebasedir = $imagebasedir . '/'; $leadon = $imagebasedir; if($leadon=='.') $leadon = ''; if((substr($leadon, -1, 1)!='/') && $leadon!='') $leadon = $leadon . '/'; $startdir = $leadon; if($_GET['dir']) { if(substr($_GET['dir'], -1, 1)!='/') { $_GET['dir'] = $_GET['dir'] . '/'; } $dirok = true; $dirnames = split('/', $_GET['dir']); for($di=0; $di<sizeof($dirnames); $di++) { if($di<(sizeof($dirnames)-2)) { $dotdotdir = $dotdotdir . $dirnames[$di] . '/'; } } if(substr($_GET['dir'], 0, 1)=='/') { $dirok = false; } if($_GET['dir'] == $leadon) { $dirok = false; } if($dirok) { $leadon = $_GET['dir']; } } $opendir = $leadon; if(!$leadon) $opendir = '.'; if(!file_exists($opendir)) { $opendir = '.'; $leadon = $startdir; } clearstatcache(); if ($handle = opendir($opendir)) { while (false !== ($file = readdir($handle))) { //first see if this file is required in the listing if ($file == "." || $file == "..") continue; if (@filetype($leadon.$file) == "dir") { if(!$browsedirs) continue; $n++; if($_GET['sort']=="date") { $key = @filemtime($leadon.$file) . ".$n"; } else { $key = $n; } $dirs[$key] = $file . "/"; } else { $n++; if($_GET['sort']=="date") { $key = @filemtime($leadon.$file) . ".$n"; } elseif($_GET['sort']=="size") { $key = @filesize($leadon.$file) . ".$n"; } else { $key = $n; } $files[$key] = $file; } } closedir($handle); } //sort our files if($_GET['sort']=="date") { @ksort($dirs, SORT_NUMERIC); @ksort($files, SORT_NUMERIC); } elseif($_GET['sort']=="size") { @natcasesort($dirs); @ksort($files, SORT_NUMERIC); } else { @natcasesort($dirs); @natcasesort($files); } //order correctly if($_GET['order']=="desc" && $_GET['sort']!="size") {$dirs = @array_reverse($dirs);} if($_GET['order']=="desc") {$files = @array_reverse($files);} $dirs = @array_values($dirs); $files = @array_values($files); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>openWYSIWYG | Select Image</title> <style type="text/css"> body { margin: 0px; } a { font-family: Arial, verdana, helvetica; font-size: 11px; color: #000000; text-decoration: none; } a:hover { text-decoration: underline; } </style> <script type="text/javascript"> function selectImage(url) { if(parent) { parent.document.getElementById("src").value = url; } } if(parent) { parent.document.getElementById("dir").value = '<?php echo $leadon; ?>'; } </script> </head> <body> <table border="0"> <tbody> <?php $breadcrumbs = split('/', str_replace($basedir."/", "", $leadon)); if(($bsize = sizeof($breadcrumbs)) > 0) { if(($bsize-1) > 0) { echo "<tr><td>"; $sofar = ''; for($bi=0;$bi<($bsize-1);$bi++) { $sofar = $sofar . $breadcrumbs[$bi] . '/'; echo '<a href="'.$_SERVER['PHP_SELF'].'?dir='.urlencode($sofar).'" style="font-size:10px;font-family:Tahoma;">» '.$breadcrumbs[$bi].'</a><br>'; } echo "</td></tr>"; } } ?> <tr> <td> <?php $class = 'b'; if($dirok) { ?> <a href="<?php echo $_SERVER['PHP_SELF'].'?dir='.urlencode($dotdotdir); ?>"><img src="images/dirup.png" alt="Folder" border="0" /> <strong>..</strong></a><br> <?php if($class=='b') $class='w'; else $class = 'b'; } $arsize = sizeof($dirs); for($i=0;$i<$arsize;$i++) { $dir = substr($dirs[$i], 0, strlen($dirs[$i]) - 1); ?> <a href="<?php echo $_SERVER['PHP_SELF'].'?dir='.urlencode($leadon.$dirs[$i]); ?>"><img src="images/folder.png" alt="<?php echo $dir; ?>" border="0" /> <strong><?php echo $dir; ?></strong></a><br> <?php if($class=='b') $class='w'; else $class = 'b'; } $arsize = sizeof($files); for($i=0;$i<$arsize;$i++) { $icon = 'unknown.png'; $ext = strtolower(substr($files[$i], strrpos($files[$i], '.')+1)); if(in_array($ext, $supportedextentions)) { $thumb = ''; if($filetypes[$ext]) { $icon = $filetypes[$ext]; } $filename = $files[$i]; if(strlen($filename)>43) { $filename = substr($files[$i], 0, 40) . '...'; } $fileurl = $leadon . $files[$i]; $filedir = str_replace($imagebasedir, "", $leadon); ?> <a href="javascript:void(0)" onclick="selectImage('<?php echo $imagebaseurl.$filedir.$filename; ?>');"><img src="images/<?php echo $icon; ?>" alt="<?php echo $files[$i]; ?>" border="0" /> <strong><?php echo $filename; ?></strong></a><br> <?php if($class=='b') $class='w'; else $class = 'b'; } } ?> </td> </tr> </tbody> </table> </body> </html> ?> insert_image.php <? require('config.inc.php'); error_reporting(0); // get the identifier of the editor $wysiwyg = $_GET['wysiwyg']; // set image dir $leadon = $rootdir.$imagebasedir; if($leadon=='.') $leadon = ''; if((substr($leadon, -1, 1)!='/') && $leadon!='') $leadon = $leadon . '/'; $startdir = $leadon; // validate the directory $_GET['dir'] = $_POST['dir'] ? $_POST['dir'] : $_GET['dir']; if($_GET['dir']) { if(substr($_GET['dir'], -1, 1)!='/') { $_GET['dir'] = $_GET['dir'] . '/'; } $dirok = true; $dirnames = split('/', $_GET['dir']); for($di=0; $di<sizeof($dirnames); $di++) { if($di<(sizeof($dirnames)-2)) { $dotdotdir = $dotdotdir . $dirnames[$di] . '/'; } } if(substr($_GET['dir'], 0, 1)=='/') { $dirok = false; } if($_GET['dir'] == $leadon) { $dirok = false; } if($dirok) { $leadon = $_GET['dir']; } } // upload file if($allowuploads && $_FILES['file']) { $upload = true; if(!$overwrite) { if(file_exists($leadon.$_FILES['file']['name'])) { $upload = false; } } $ext = strtolower(substr($_FILES['file']['name'], strrpos($_FILES['file']['name'], '.')+1)); if(!in_array($ext, $supportedextentions)) { $upload = false; } if($upload) { move_uploaded_file($_FILES['file']['tmp_name'], $leadon . $_FILES['file']['name']); } } if($allowuploads) { $phpallowuploads = (bool) ini_get('file_uploads'); $phpmaxsize = ini_get('upload_max_filesize'); $phpmaxsize = trim($phpmaxsize); $last = strtolower($phpmaxsize{strlen($phpmaxsize)-1}); switch($last) { case 'g': $phpmaxsize *= 1024; case 'm': $phpmaxsize *= 1024; } } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>openWYSIWYG | Insert Image</title> <script type="text/javascript" src="../../scripts/wysiwyg-popup.js"></script> <script language="JavaScript" type="text/javascript"> /* ---------------------------------------------------------------------- *\ Function : insertImage() Description : Inserts image into the WYSIWYG. \* ---------------------------------------------------------------------- */ function insertImage() { var n = WYSIWYG_Popup.getParam('wysiwyg'); // get values from form fields var src = document.getElementById('src').value; var alt = document.getElementById('alt').value; var width = document.getElementById('width').value var height = document.getElementById('height').value var border = document.getElementById('border').value var align = document.getElementById('align').value var vspace = document.getElementById('vspace').value var hspace = document.getElementById('hspace').value // insert image WYSIWYG.insertImage(src, width, height, align, border, alt, hspace, vspace, n); window.close(); } /* ---------------------------------------------------------------------- *\ Function : loadImage() Description : load the settings of a selected image into the form fields \* ---------------------------------------------------------------------- */ function loadImage() { var n = WYSIWYG_Popup.getParam('wysiwyg'); // get selection and range var sel = WYSIWYG.getSelection(n); var range = WYSIWYG.getRange(sel); // the current tag of range var img = WYSIWYG.findParent("img", range); // if no image is defined then return if(img == null) return; // assign the values to the form elements for(var i = 0;i < img.attributes.length;i++) { var attr = img.attributes[i].name.toLowerCase(); var value = img.attributes[i].value; //alert(attr + " = " + value); if(attr && value && value != "null") { switch(attr) { case "src": // strip off urls on IE if(WYSIWYG_Core.isMSIE) value = WYSIWYG.stripURLPath(n, value, false); document.getElementById('src').value = value; break; case "alt": document.getElementById('alt').value = value; break; case "align": selectItemByValue(document.getElementById('align'), value); break; case "border": document.getElementById('border').value = value; break; case "hspace": document.getElementById('hspace').value = value; break; case "vspace": document.getElementById('vspace').value = value; break; case "width": document.getElementById('width').value = value; break; case "height": document.getElementById('height').value = value; break; } } } // get width and height from style attribute in none IE browsers if(!WYSIWYG_Core.isMSIE && document.getElementById('width').value == "" && document.getElementById('width').value == "") { document.getElementById('width').value = img.style.width.replace(/px/, ""); document.getElementById('height').value = img.style.height.replace(/px/, ""); } } /* ---------------------------------------------------------------------- *\ Function : selectItem() Description : Select an item of an select box element by value. \* ---------------------------------------------------------------------- */ function selectItemByValue(element, value) { if(element.options.length) { for(var i=0;i<element.options.length;i++) { if(element.options[i].value == value) { element.options[i].selected = true; } } } } </script> </head> <body bgcolor="#EEEEEE" marginwidth="0" marginheight="0" topmargin="0" leftmargin="0" onLoad="loadImage();"> <table border="0" cellpadding="0" cellspacing="0" style="padding: 10px;"> <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>?wysiwyg=<?php echo $wysiwyg; ?>" enctype="multipart/form-data"> <input type="hidden" id="dir" name="dir" value=""> <tr> <td style="vertical-align:top;"> <span style="font-family: arial, verdana, helvetica; font-size: 11px; font-weight: bold;">Insert Image:</span> <table width="380" border="0" cellpadding="0" cellspacing="0" style="background-color: #F7F7F7; border: 2px solid #FFFFFF; padding: 5px;"> <?php if($allowuploads) { if($phpallowuploads) { ?> <tr> <td style="padding-top: 0px;padding-bottom: 0px; font-family: arial, verdana, helvetica; font-size: 11px;width:80px;">Upload:</td> <td style="padding-top: 0px;padding-bottom: 0px;width:300px;"><input type="file" name="file" size="30" style="font-size: 10px; width: 100%;" /></td> </tr> <tr> <td style="padding-top: 0px;padding-bottom: 2px;font-family: tahoma; font-size: 9px;"> </td> <td style="padding-top: 0px;padding-bottom: 2px;font-family: tahoma; font-size: 9px;">(Max Filesize: <?php echo $phpmaxsize; ?>KB)</td> </tr> <?php } else { ?> <tr> <td style="padding-bottom: 2px; padding-top: 0px; font-family: arial, verdana, helvetica; font-size: 11px;" colspan="2"> File uploads are disabled in your php.ini file. Please enable them. </td> </tr> <?php } } ?> <tr> <td style="padding-bottom: 2px; padding-top: 0px; font-family: arial, verdana, helvetica; font-size: 11px;" width="80">Image URL:</td> <td style="padding-bottom: 2px; padding-top: 0px;" width="300"><input type="text" name="src" id="src" value="" style="font-size: 10px; width: 100%;"></td> </tr> <tr> <td style="padding-bottom: 2px; padding-top: 0px; font-family: arial, verdana, helvetica; font-size: 11px;">Alternate Text:</td> <td style="padding-bottom: 2px; padding-top: 0px;"><input type="text" name="alt" id="alt" value="" style="font-size: 10px; width: 100%;"></td> </tr> </table> <table width="380" border="0" cellpadding="0" cellspacing="0"><tr><td style="vertical-align:top;"> <span style="font-family: arial, verdana, helvetica; font-size: 11px; font-weight: bold;">Layout:</span> <table width="180" border="0" cellpadding="0" cellspacing="0" style="background-color: #F7F7F7; border: 2px solid #FFFFFF; padding: 5px;"> <tr> <td style="padding-bottom: 2px; padding-top: 0px; font-family: arial, verdana, helvetica; font-size: 11px;">Width:</td> <td style="width:60px;padding-bottom: 2px; padding-top: 0px;"><input type="text" name="width" id="width" value="" style="font-size: 10px; width: 100%;"></td> </tr> <tr> <td style="padding-bottom: 2px; padding-top: 0px; font-family: arial, verdana, helvetica; font-size: 11px;">Height:</td> <td style="padding-bottom: 2px; padding-top: 0px;"><input type="text" name="height" id="height" value="" style="font-size: 10px; width: 100%;"></td> </tr> <tr> <td style="padding-bottom: 2px; padding-top: 0px; font-family: arial, verdana, helvetica; font-size: 11px;">Border:</td> <td style="padding-bottom: 2px; padding-top: 0px;"><input type="text" name="border" id="border" value="0" style="font-size: 10px; width: 100%;"></td> </tr> </table> </td> <td width="10"> </td> <td style="vertical-align:top;"> <span style="font-family: arial, verdana, helvetica; font-size: 11px; font-weight: bold;"> </span> <table width="200" border="0" cellpadding="0" cellspacing="0" style="background-color: #F7F7F7; border: 2px solid #FFFFFF; padding: 5px;"> <tr> <td style="width: 115px;padding-bottom: 2px; padding-top: 0px; font-family: arial, verdana, helvetica; font-size: 11px;" width="100">Alignment:</td> <td style="width: 85px;padding-bottom: 2px; padding-top: 0px;"> <select name="align" id="align" style="font-family: arial, verdana, helvetica; font-size: 11px; width: 100%;"> <option value="">Not Set</option> <option value="left">Left</option> <option value="right">Right</option> <option value="texttop">Texttop</option> <option value="absmiddle">Absmiddle</option> <option value="baseline">Baseline</option> <option value="absbottom">Absbottom</option> <option value="bottom">Bottom</option> <option value="middle">Middle</option> <option value="top">Top</option> </select> </td> </tr> <tr> <td style="padding-bottom: 2px; padding-top: 0px; font-family: arial, verdana, helvetica; font-size: 11px;">Horizontal Space:</td> <td style="padding-bottom: 2px; padding-top: 0px;"><input type="text" name="hspace" id="hspace" value="" style="font-size: 10px; width: 100%;"></td> </tr> <tr> <td style="padding-bottom: 2px; padding-top: 0px; font-family: arial, verdana, helvetica; font-size: 11px;">Vertical Space:</td> <td style="padding-bottom: 2px; padding-top: 0px;"><input type="text" name="vspace" id="vspace" value="" style="font-size: 10px; width: 100%;"></td> </tr> </table> </td> </tr> </table> </td> <td style="vertical-align: top;width: 150px; padding-left: 5px;"> <span style="font-family: arial, verdana, helvetica; font-size: 11px; font-weight: bold;">Select Image:</span> <iframe id="chooser" frameborder="0" style="height:165px;width: 180px;border: 2px solid #FFFFFF; padding: 5px;" src="select_image.php?dir=<?php echo $leadon; ?>"></iframe> </td> </tr> <tr> <td colspan="2" align="right" style="padding-top: 5px;"> <input type="submit" value=" Submit " onclick="insertImage();return false;" style="font-size: 12px;"> <?php if ( $allowuploads ) { ?> <input type="submit" value=" Upload " style="font-size: 12px;"> <?php } ?> <input type="button" value=" Cancel " onclick="window.close();" style="font-size: 12px;"> </td> </tr> </form> </table> </body> </html> ?> Those are the codes that insert to a WYSIWYG JS popup Link to comment https://forums.phpfreaks.com/topic/153494-image-upload-problem/#findComment-806519 Share on other sites More sharing options...
gaza165 Posted April 10, 2009 Share Posted April 10, 2009 change your error reportting to E_ALL <?php error_reporting(E_ALL); ?> see if it brings back any errors and post them Link to comment https://forums.phpfreaks.com/topic/153494-image-upload-problem/#findComment-806521 Share on other sites More sharing options...
gnawz Posted April 10, 2009 Author Share Posted April 10, 2009 I got these errors... Notice: Undefined variable: rootdir in C:\xampp\htdocs\mgs\admin\news\addons\imagelibrary\insert_image.php on line 13 Notice: Undefined index: dir in C:\xampp\htdocs\mgs\admin\news\addons\imagelibrary\insert_image.php on line 20 Notice: Undefined index: dir in C:\xampp\htdocs\mgs\admin\news\addons\imagelibrary\insert_image.php on line 20 Notice: Undefined index: file in C:\xampp\htdocs\mgs\admin\news\addons\imagelibrary\insert_image.php on line 46 How come it works at localhost? Link to comment https://forums.phpfreaks.com/topic/153494-image-upload-problem/#findComment-806544 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.