Jump to content

Problem with upload folder


felicita

Recommended Posts

i have this page for upload:

 

<?php
require ('incs/db.php');?>
<?php require_once ('incs/funcs.php');?>

<?php


if (array_key_exists('upload', $_POST)) {
         $directory = str_replace(basename($_SERVER['PHP_SELF']),'',$_SERVER['PHP_SELF']);
           $uploadHandler = $_SERVER['DOCUMENT_ROOT']. $directory . 'images/';
      //  $uploadHandler = "echtitipi".$_SERVER['HTTP_HOST']. '/images/';
                 $max_file_size = 30000;
         define('UPLOAD_DIR', $uploadHandler);
         $ext= end(explode(".",  $_FILES['image']['name']));
         $name = rand(1111111,9999999).'.'.$ext;   
                 if (move_uploaded_file($_FILES['image']['tmp_name'], $uploadHandler. $name))
         {
             $upload = true;
             $title = $_POST ['title'];
             $sql = "INSERT INTO photo (id, keyword, photoName)
             VALUES ('','$title','$name')
             ";
            $result = mysql_query ( $sql, $con );
         }
         else
         {
             $upload = false;
             $msg = 'Cant Upload!';
         }
    }
?>
<?php

include ('incs/header.php');
?>
<?php

getUrlQuery();

?>
<script language="javascript">
<!--

function pick(symbol, path) {
  if (window.opener && !window.opener.closed)
    window.opener.document.form.img.value = symbol;
window.opener.document.form.imgbox.src = path;
  window.close();
}

// -->
</script>
<form action="upload.php" method="post" enctype="multipart/form-data" name="uploadImage" id="uploadImage">
            <p>
                <label for="image">
                    Tanım:
                </label>
                <input type="text" name="title" id="title" />
                <label for="image">
                    Upload image:
                </label>
                <input type="file" name="image" id="image" />
            </p>
            <p>
                <input type="submit" name="upload" id="upload" value="Upload" />
            </p>
        </form>
<?php 
     if($upload == true)
     {
         echo "<a href=\"javascript:pick('$name','images/$name')\"><img src=\"http://www.webmasterforums.com/images/$name\" border=\"0\" alt=\"kullan\"></a>";
     }
?>
    
    <?php
include ('incs/footer.php');
?>

 

 

this upload image to curretnt root's images folder. My current folder is admin:

 

 

root/admin/images

 

root/images

 

when i use

$uploadHandler = "http://".$_SERVER['HTTP_HOST']. '/images/'; 

 

script doesnot work.

 

<?php
if($upload == true)
{
echo "<a href=\"javascriptick('$name','{$uploadHandler}$name')\"><img src=\"{$uploadHandler}$name\" border=\"0\" alt=\"kullan\"></a>";
}
?> 

 

the image couldnot add to editor. I guess There is a problem with javascript.

what is wrong in script

thanks in advance

 

(upload.php is in root/admin/ and i want to upload image to root/images!)

Link to comment
https://forums.phpfreaks.com/topic/182763-problem-with-upload-folder/
Share on other sites

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.