Author Topic: quick help with a directory path issue when uploading an image ..  (Read 411 times)

0 Members and 1 Guest are viewing this topic.

Offline imarockstarTopic starter

  • Enthusiast
    • View Profile
I am having trouble uploading a file based on the image directory I need to upload it with ...

here is the original code :

Code: [Select]
<?php
   
// Edit upload location here
   
$destination_path getcwd().DIRECTORY_SEPARATOR;

   
$result 0;
   
   
$target_path $destination_path basename$_FILES['myfile']['name']);

   if(@
move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
      
$result 1;
   }
   
   
sleep(1);
?>


<script language="javascript" type="text/javascript">window.top.window.stopUpload(<?php echo $result?>);</script>   

the scripts works like this .. but it uploads it in the directory that this script is in which is here :

/public_html/scripts/upload.php

i need the images to be moved to this path :

/public_html/images/trainerpics/

but I can figure out how to change the script for that ...

Offline Andy-H

  • Devotee
  • Gender: Male
    • View Profile
Re: quick help with a directory path issue when uploading an image ..
« Reply #1 on: July 03, 2009, 04:02:56 PM »
Code: [Select]
<?php
   
// Edit upload location here
   
$destination_path getcwd().DIRECTORY_SEPARATOR;

   
$result 0;
   
   
$target_path $destination_path basename$_FILES['myfile']['name']);

   if( 
move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path) === True ) {
      
$result 1;
   }
   
   
sleep(1);
?>


<script language="javascript" type="text/javascript">window.top.window.stopUpload(<?php echo $result?>);</script>  

Why do you access the js window object twice?

Also can you do a var_dump on $target_path please?
Mess with the best, die("Like the rest...");

Offline imarockstarTopic starter

  • Enthusiast
    • View Profile
Re: quick help with a directory path issue when uploading an image ..
« Reply #2 on: July 03, 2009, 04:13:00 PM »
Im not sure i didt write the script ...

this works :

$destination_path = getcwd().DIRECTORY_SEPARATOR;

but i need it somthing like this :

$destination_path = "/public_html/images/trainerpics/";

but thats not uploading the image .. i am sure my formatting is wrong

Offline imarockstarTopic starter

  • Enthusiast
    • View Profile
Re: quick help with a directory path issue when uploading an image ..
« Reply #3 on: July 03, 2009, 04:13:59 PM »
here is the script thats post t the code i placed above ..

Code: [Select]
<script language="javascript" type="text/javascript">
<!--
function startUpload(){
      document.getElementById('f1_upload_process').style.visibility = 'visible';
      document.getElementById('f1_upload_form').style.visibility = 'hidden';
      return true;
}

function stopUpload(success){
      var result = '';
      if (success == 1){
         result = '<span class="msg">The file was uploaded successfully!<\/span><br/><br/>';
      }
      else {
         result = '<span class="emsg">There was an error during file upload!<\/span><br/><br/>';
      }
      document.getElementById('f1_upload_process').style.visibility = 'hidden';
      document.getElementById('f1_upload_form').innerHTML = result + '<label>File: <input name="myfile" type="file" size="30" /><\/label><label><input type="submit" name="submitBtn" class="sbtn" value="Upload" /><\/label>';
      document.getElementById('f1_upload_form').style.visibility = 'visible';     
      return true;   
}
//-->
</script>   
</head>

<body>
       <div id="container">
            <div id="header"><div id="header_left"></div>
            <div id="header_main">Max's AJAX File Uploader</div><div id="header_right"></div></div>
            <div id="content">
                <form action="scripts/upload.php" method="post" enctype="multipart/form-data" target="upload_target" onsubmit="startUpload();" >
                     <p id="f1_upload_process">Loading...<br/><img src="images/ajaxupload/loader.gif" /><br/></p>
                     <p id="f1_upload_form" align="center"><br/>
                         <label>File: 
                              <input name="myfile" type="file" size="30" />
                         </label>
                         <label>
                             <input type="submit" name="submitBtn" class="sbtn" value="Upload" />
                         </label>
                     </p>
                     
                     <iframe id="upload_target" name="upload_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe>
                 </form>
             </div>
             <div id="footer"><a href="http://www.ajaxf1.com" target="_blank">Powered by AJAX F1</a></div>
         </div>
                 
</body> 

Offline Zanus

  • Staff Alumni
  • Addict
  • *
  • Gender: Male
    • View Profile
Re: quick help with a directory path issue when uploading an image ..
« Reply #4 on: July 03, 2009, 04:18:40 PM »
using getcwd() will get you the Current Working Directory (cwd)
which is why it uploads to the scripts directory

echo out $destination_path
play around wiath what that outputs to change it

Offline Andy-H

  • Devotee
  • Gender: Male
    • View Profile
Re: quick help with a directory path issue when uploading an image ..
« Reply #5 on: July 03, 2009, 04:18:58 PM »
Code: [Select]
<?php
   
// Edit upload location here
   
$destination_path getcwd().DIRECTORY_SEPARATOR;

   
$result 2;
   
   
$target_path $destination_path basename$_FILES['myfile']['name']);
   die(
$target_path);
   if( 
move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path) === True ) {
      
$result 1;
   }
   
   
sleep(1);
?>


<script language="javascript" type="text/javascript">window.top.window.stopUpload(<?php echo $result?>);</script>   

What does that output?
Mess with the best, die("Like the rest...");

PHP Freaks Forums

« on: »

Tired of these ads? Purchase a supporter subscription to get rid of them.