imarockstar Posted July 3, 2009 Share Posted July 3, 2009 I am having trouble uploading a file based on the image directory I need to upload it with ... here is the original code : <?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 ... Quote Link to comment https://forums.phpfreaks.com/topic/164698-quick-help-with-a-directory-path-issue-when-uploading-an-image/ Share on other sites More sharing options...
Andy-H Posted July 3, 2009 Share Posted July 3, 2009 <?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? Quote Link to comment https://forums.phpfreaks.com/topic/164698-quick-help-with-a-directory-path-issue-when-uploading-an-image/#findComment-868536 Share on other sites More sharing options...
imarockstar Posted July 3, 2009 Author Share Posted July 3, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/164698-quick-help-with-a-directory-path-issue-when-uploading-an-image/#findComment-868539 Share on other sites More sharing options...
imarockstar Posted July 3, 2009 Author Share Posted July 3, 2009 here is the script thats post t the code i placed above .. <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> Quote Link to comment https://forums.phpfreaks.com/topic/164698-quick-help-with-a-directory-path-issue-when-uploading-an-image/#findComment-868540 Share on other sites More sharing options...
Zane Posted July 3, 2009 Share Posted July 3, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/164698-quick-help-with-a-directory-path-issue-when-uploading-an-image/#findComment-868542 Share on other sites More sharing options...
Andy-H Posted July 3, 2009 Share Posted July 3, 2009 <?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? Quote Link to comment https://forums.phpfreaks.com/topic/164698-quick-help-with-a-directory-path-issue-when-uploading-an-image/#findComment-868543 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.