Recent Feedback
i want to copy a file from a /pending/ directory to a /storage/ directory. the /pending/ file is called $string_final, the /storage/ file is called $painti am using a copy statement and then an unlink statementproblem: the syntax for using a variable name in the directory name doesn't work and it executes as soon as the page loads and not just after the 'submit' button is pressed
Optional Information: Language (or Software): PHP Already Tried: if i hard code the file name the copy works but not with the variable, it must be a syntax problem i can't get it to only execute after the submit at all, i tried if(isset(submit)) but to no avail or if some field has content but it ignores it
Hello, I can help you with this. Please upload the file you are using to http://wikisend.com at your convenience so that I can have a look.
i uploaded index2.php to wikisend.com and it showed uploaded but went directly to HTTP 500 internal server error after that so i don't know if it took. i'm also not sure how you are going to see it as my file. please let me know. thx
If you did not see a download link appear then you probably encounted an error (that happens sometimes). Try using http://ge.tt
ge.tt said it copied to http://www.ge.tt/46AGpJJ/v/0?c
let me know if thats enough information
I got it. I will take a look at it. If you happen to have a formatted copy that is more readable please upload that version instead.
i don't understand what you are asking. what i uploaded should be what i'm working with. does it look weird or something???
The code I got was not indented so it is a bit harder to read given the size of the file so I was just wondering if you had a better formatted version. It's not a big deal if you don't, I will sort through what you sent.
Please find the updated file at http://ge.tt/61g0EKJ/v/0It shoudl move the $string_final filename in the pending folder to a file named $paint in the storage folder. This will also work when the "Save Painting" button is clicked. Please let me know if it works for you as I can't test it and I will make any adjustments you need.Remember, if for any reason you’re unsatisfied, we can continue our conversation until you’ve received the information you’re looking for. If I haven’t answered your question, please let me know and I’ll be happy to answer any other follow-up questions you might have.
i uploaded the index2.php you modified and ran it several times, the rename function you created did nothing, no files were copied or deleted. now what???
i just tried adding an 'echo' statement inside the if statement you made. when i reloaded and ran the php it said hello so that indicates that is sees the statement as true
i also copied your 'rename' statement outside the if statement and put it inside an 'echo' line and it shows to the screen with both variables and directory structures in the right sequence
it really looks like it should work
i also checked all 3 relevelant directories on my site and there is no php_error.php file in any of them showing that no significant error was created by running the script in that directory
i don't know if you can tell but i keep editing this and adding comments and i think of things, lol
what about this??? i have selected the jpg file in the code above to show the name and display the image. did you try to execute the code? well...maybe i can't rename the file if its basically IN USE, it makes sense, if thats so, how can i release the file so the rename works?
just more food for thought
As I mentioned above I am not able to test this code since it is written for whatever application it is that you have setup along with the directory structure and so on. You have confirmed that the correct values are present for $string_final and $paint, so that's a start. I don't see how the file could be in use unless there is something else taking place that I am not aware of. Does the script have access to write to the storage directory? You can temporarily set the permissions on storage to 777 to check if that's the issue. Also confirm that the path is correct for /home/davidsdo/... etc.
ok, i did some more testing, i copied the code from the submit button down to the if statement with the rename inside to another php file.
i ran it and nothing happened AGAIN!!!
then i commented out the input button and removed $submit1 from the if statement
it worked YEAH!!!
so now the question is why doesn't the submit1 button not work?
below are the lines. i remarked out the first two and removed the $submit1 && from the 3rd one. what do you think is wrong???
<input type='submit' name='submit1' value='Save Painting' />
$submit1=$_POST['submit1'];
if ($submit1 && $paint == true) {
Hard to say without a look at the actual webpage that is generated but you can try the following:if ($_POST && $paint == true) {...
the actual webpage is the index2.php i sent you. if you remove the references to opening the database and change the directory structure to what you have everything will work. let me know if this helps. there are no other files that interact with this one, just don't use the buttons on the top left. they are connected to other files but are not part of the problem at hand.
thanks
I could not reproduce it with exactly since I don't have all of those text files but after removing those files (categories.txt, years.txt, etc.) I was able to use the code as expected. Did you have a chance to check the permissions and file path as I mentioned before?
i did test that and without the if submit1 in there the rename command works fine and moves the file from one directory to another, therefore, i don't see how it could be a permissions issue, it now doesn't work with the submit1 == true part of the if statement
I wasn't aware that you got it working to move the file, wasn't that the issue you were facing in your question?
yes partly, i wanted to move the file and get it to only execute when the submit button was pressed. now we just have the submit button problem. if i take the $submit1 portion of the if statement out it executes when the php file loads, if i use the $submit1 in the if statement it doesn't work at all
my bad, i'm doing so much i can't keep up with what i'm saying
the rename works in a test file but not in the actual index2.php file and still without the $submit1 portion
i don't know about the submit button portion but i'm thinking that there is a in use issue with the index2.php file because the test.php file does not look at the file before doing the move. i am going to upload the test.php file that does work and will post the link for you to look at in a minute.
http://ge.tt/9mR8mOJ/v/0
i just tried inserting an IMG statement before the submit button hardcoding the Connection.jpg file. it doesn't display because it immediately copied the file and had nothing to display in the /pending/directory.
i inserted thhe $submit1 && into the if statement and it shows the picture but again will not execute the rename command.
something is definately wrong here. there must be something that we are missing. i am going to continue to google and see what i can come up with. i will post any findings here. you please do the same.
i just tried coding the rename command into the submit button command itself as an onClick and an onSubmit command. it still executes when the page loads. i don't see why it wouldn't wait until the button is clicked when its inside the button itself. who the he** knows.
HELP!!!!!!!
My test yesterday using the file you sent me worked using $submit1. It makes logical sense. When the form is submitted $_POST['submit1'] contains the value of the button, Save Painting. This evaluates to true for a !empty test. To demonstrate place:var_dump(!empty($submit1)); before if ($painting...). Also do a print_r($_POST); to see if anything is passed for submit1 (as it could be conflicting with something else on the page). Everything should also be wrapped inside of a block for handling POST requests only as shown below:There is also some inconsistency between in the variable naming regarding "$paint" and "$painting". Please be sure to update your code as shown below to either use the variable named $paint OR $painting. $painting is used below and should work.if ($_POST) {$submit1=$_POST['submit1'];$filename=$_POST['painting'].".jpg";$painting=$_POST['painting'];$string_final="Asanti.jpg";print_r($_POST); // check to see that submit1 is set in herevar_dump(!empty($submit1)); // another check for submit1if ($submit1 && $painting) { rename('/home/davidsdo/public_html/marknutt/photos/pending/' . $string_final,'/home/davidsdo/public_html/marknutt/photos/storage/' . $painting); $inputarray="0";}}You test.php file won't work for submit1 because the button is not in a form.
i appreciate all your work on this issue. i have dealt with several other programmers and they could not fix the problem. i have not tried your last recommendations but will. i have to go to the hospital today and stay until tomorrow night. unfortunately they do not have internet so i can't work. i will resume testing on either friday night if i get back home early enough or saturday. please do not close this question until after i test it. thanks again.......david
I'm hoping it is the difference in the variable name, in the original code the variable was declared as $paint but the if statement had $painting, which would explain why it was not performing the operation. Anyway, I hope all goes well at the hospital. The question will remain on here till you get back.
hi, i found somewhere to get online for awhile. we are really close. the print_r command helps. once the form is submitted once the next time its run the painting field is populated with the name from the first run. i tried a 'function prepopulate' above the input for the painting field, it loads but actually doesn't do anything, can you show me the syntax and placement of a 'function prepopulate'?
i have:
function prepopulate($painting) { $painting=" ";}
it is in the same form. like i said just above the input field for painting. i put:
value="<?php prepopulate('painting');?>"
am i missing something???
if you want to prepopulate the painting field with the last value you can do something like (updated line): p, li { white-space: pre-wrap; }
echo "<center>"; echo "Painting Title:"; echo "<input type='text' name='painting' size='30' " . (isset($_POST['painting']) ? $_POST['painting'] : '') . " />"; echo "</center>";
What it does is check to see if a value is present from a previous submission and if it is assign it to the input's value, if not then nothing is displayed.
hi,
i'm back home. but....i wanted just the opposite. i want to prepopulate the painting field with blank. i will also apply this to submit1. both of these retain information from previous submittions. this was detected from your idea of print_r.
With the code I provided, it will initially be blank then after submitting the form it will have the value that was entered by the user. That seems to be what you are describing.
the "p, li { white-space: pre-wrap; } " causes a syntax error
i'm a dodo head. of course that line goes in the head. got it
i'm close now, it places the right variables where they below. it still didn't work though so i echo'd the rename command and noticed that $string_final is blank when it tries to rename so the bool is false. i just don't know so i uploaded the file to http://ge.tt/3rE04VJ/v/0
of course i'll keep looking but if you would too i'd appreciate it.
do you ever have cases that last as long as this one?
its tiring
If $string_final is empty it would have something to do with $arr and/or $inputarray. Can you put print_r/var_dump statements to see what is in those variables to ensure they have the values that you expect?
i'm getting tired of this, not you, just the problem. now it kinda works. it does the rename but....it actually deletes the whole /pending/ directory and actually creates a subdirectory under the /storage/ directory with the $filename name and puts the file desired under that directory.
it still appears from displaying the rename statement and the array that the $string_final is infact blank. what in the world.
i again have uploaded index2.php
http://www.ge.tt/19n6ebJ/v/0?c
HELP!!!
i would really luv to get this damn thing running today :)
A couple things: if $string_final is empty then the directory would be renamed (and not a file, since there would be no file specified). If $string_filnal is blank it depends on several other variables, I'm not sure if you saw this in my last message If $string_final is empty it would have something to do with $arr and/or $inputarray. Can you put print_r/var_dump statements to see what is in those variables to ensure they have the values that you expect?$string/$string_final comes from $arr[$inputarray] so the source of the problem most likely has something to do with one of those variables. Please print them out to ensure they contain the correct values.
i see what your saying, i do see that my variable is empty so it makes sense about the directories being created and deleted,
i have done a print_r/var_dump and yes it is empty, i see that
the $arr[$inputarray] works at the top of the file when it displays the content, i just don't know why is all of a sudden doesn't show at the portion where submit is hit
This is another issue which I still cannot test on my end given the way this is written. I will have to opt-out so that another expert can assist you with this.
I would be glad to finish this task for you.To help me better understand the current status of your problem, could you describe the task you are trying to perform and which part is still not working?
ok david,
i have two directories with photos, /pending/ /storage/
i have been trying to do a 'rename' after the submit button is pressed.
the /pending/ file is displayed but the filename for the /storage/ is user entered before hitting the submit button
this process has not worked completely at all, i originally opened this case on 6/2 and has been closed several time by other experts
different answers i have been given solves a portion but then causes another
currently i have the 'rename' working but the filename for the /pending/ directory is not inserting into the command so instead it deletes the /pending/ directory and creates another subdirectory under the /storage/ directory with the name of the destination input filename
http://ge.tt/19n6ebJ/v/0 has a copy of the index2.php file for your review.
please help
ok. so if I have an image file 'test.jpg' stored in the same directory of the php file, can you walk me through the steps you take on the PHP page to do this operation?
the data 'jpg' files are never in the same directory as the php files. php files are under the root directory of the site. files are uploaded to the /pending/ directory and then displayed as an array on screen. the user has an input field to select the 'jpg' needed. they then enter on the field and the right side of the screen shows the jpg filename on the right with an image of the file. they then add a ton of variables associated to this file including a new filename for permanent storage. then they hit submit, the new named file is moved to /storage/ directory (in theory) and the variables for the file and its new name are all stored in a dbms.
almost everything works. the problem is that the rename command was executing before the submit button was pressed. i am now using isset to ensure the submit button is pressed and the new filename the user inputted has been typed.
if you notice the index2.php file i sent, there are two variables for the rename statement, the 2nd one for the destination filename works but the 1st one for the pending name is XXXXX XXXXX have tried a var_dump and it does show empty,
i'm obviously missing something but i think i'm close, can you weed all this out???
Ok when I open the PHP file I see all the items in the current directory as well as all sub-directories (not just pending) inside 'Array'. Is this the expected behavior?Also could you upload any other files that are required for this to run? It appears I will need all of the TXT files in your 'variables' directory.
hi david, i'm not sure why you closed my question. i have a business and can only check my laptop from time to time during the day.
the text files in the /variables/ directory is only used if you select the variables option on the menu. this option is not used in my problem so the files are not required. just so you know the txt files in question are user entered data into each file from another menu and these entries are used to display dropdown lists the user can select. it has no bearing on this issue and is not required for the website to function.
as to your original question. at the top of the php file there is a commented section for displaying the array. this is where the /pending/ directory contents are displayed. i know if this directory does not exist then all directories and files are listed. if it does than only the jpg files in the /pending/ are displayed in the array.
don't worry, your question may have timed out but it is still open. the way your file is coded, it will fail and exit if all of those TXT are NOT provided. as a temporary fix i have commented out all requests to the files to prevent this, but this may interfer with your problem later on.also I currently have a JPG in the pending directory but I am still seeing all directories files in the array variables. can you point out which line to uncomment to fix this?
the directory is refferenced on line 95. this is where i change to the /pending/ directory and create the array sequence.
OK I have that part working now.Could you describe an example to me that you have tried that doesn't work?Please tell me exactly what you are clicking on and where and what you are typing into fields on the page as well.This way I can recreate your steps on my copy and find the source of the problem.
under file to process type any number cooresponding to anything on the list to the left. under filename type any unique name. press 'save painting'. this should copy the file from the /pending/ directory to the /storage/ directory with the input file name. thats all i want. but only when the submit button is pressed.
I found the problem. I commented out these lines and replaced with the line below them://$string="$arr[$inputarray]";//$string_final=substr($string,2,30)."\n";$string_final = $_POST['inputarray'];Replace your index2.php with this one: http://www.wikisend.com/download/477136/index2.phpKeep in mind I still have the variable TXT files checks commented out, so you will need to remove the lines:/* START TXT FILESandEND TXT FILES */
i did as you suggested and no difference, i downloaded the index2.php, unremarked out the section you remarked out and uploaded to my server. it still doesn't see the $string_final and deletes the /pending/ directory and creates a directory with that new file name under the /storage/ directory??? i reprepped the pending directory, i will leave it and you can check it out at www.davidsdomaindesign.com/marknutt/index2.php but you can only execute it once and see the echo'd statement then the /pending/ directory will be gone and i'll have to reset it again, let me know.
This is the test i ran that worked as you instructed:1. put a jpg image into pending folder2. type name of jpg (including extension) into 'file to process' field3. type name of new title into 'painting title' field4. hit 'save painting' button5. file is moved from pending folder to storage folder with new nameIs the the test you tried?
i think i see the difference, the 'file to process' is the number associated to the array shown on the left side not a file name. typing this number and pressing enter shows the associated file name to the top of that number above the input field for 'painting title'.
I see, I misread your previous post. I will change it to use the number.
OK, the number identifier for 'File to Process' works now. I had to change how $string_final was stored around line 140:$string="$arr[$inputarray]";$string_final=substr($string,2);http://www.wikisend.com/download/644098/index2.php
awesome, IT WORKS....almost :( your right if you type file to process and type the painting name it movies the file, unfortunately, you need to be able to type file to process (and press enter), this is how the picture is displayed and the variables are entered (the ones you echo'd out), then pressing submit should then move the file and it will write a record to a database.
can you do that???
otherwise your right, it does work and i probably should have clarified.
sorry
Well the standard is for HTML forms to behave the same whether you use the ENTER key or the form SUBMIT button. It is possible to hijack this process, but I wouldn't recommend it.Is there a single action that would be suitable for both the ENTER key and SUBMIT that might be acceptable to you?
i think i understand what you are saying. pressing enter after typing the file to process activates the right side of the page and allows all the other entered data to be written to the database. the submit writes the dbms record and moves the file to /storage/. is there another way to seperate these two functions?
Well you could use two seperate forms each with their own submit button, but this would be difficult to do since they both redirect to the same page.It might be possible to simply have the submit button behave differently depending on if file to process is provided or not. But then this would be confusing to the user. Is this page only going to be used by you, or do you have an audience that is expected to use this?
i am designing the page, others will be running it. think about this though, entering the 'file to process' does not need to go anywhere, it just pulls local information and displays it, its the submit the needs to run another php file. does that make a difference? can we segerate them
to my knowledge, both the ENTER key press and the Submit button are POSTing data to index2.php and not a separate PHP file.But before we continue, has your original problem been solved? I read through your original question and that part appears to be working now, can you double-check?
technically it was resolved, i asked to have the copy/move statements work, that does, it just doesn't work at the right time, i.e. pressing submit not just pressing enter. therefore i will say yes. now how do i close this ticket with you and ensure i get you when i open the next one? i don't want to have to start all over again with someone else. hell no LOL
let me know
To close the question simply rate one of my answers with a 3 or higher rating.To open a new question to me you can click on my name and on my profile page, and ask the question in the question box.
Experience: 6+ years of programming expertise