I have an upload image page in my site and it works pretty well in my localhost.
However, when i uploaded it in my server, the error message I have in my php is displayed. What seems to be the problem? :o
I have an upload image page in my site and it works pretty well in my localhost.
However, when i uploaded it in my server, the error message I have in my php is displayed. What seems to be the problem? :o
No clue.
Post up the error and some code.
Thanks... here are the codes.
<?php $saveto = $_POST["saveto"];//get action variable from browsefile ?>
// one fault resolved because of this thread but did not solve the main problem<?
if(file_exists("../images/$saveto/" + $_FILES['txt_file']['name'])) {
echo("<center>
<font class=\"blackHeader\"><b>File already exists! Please rename the file.</b></font> <br /><br />
<a href=\"javascript: window.close()\" class=\"black\"><u>close this window</u></a>
</center>
");
}
else {
if(is_file($txt_file)) {$target_path = "../images/$saveto/";
//Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $FILES['txt_file']['name']);
$FILES['txt_file']['tmp_name'];if(move_uploaded_file($_FILES['txt_file']['tmp_name'], $target_path)) {
echo("<script language=\"javascript\" type=\"text/JavaScript\">
<!--
window.opener.document.frm.$frm.value=\"$txt_file_name\";
window.opener.focus();
window.close();
//-->
</script>");
}
else {
echo("<div align=\"center\"><font class=\"blackHeader\">Could not copy file. Your file must be corrupted!</font></div>");
}
}
}
?>
check folder permissions
Thanks a lot.
So you think it's within my code or folder permission in my server?
Sorry... I'm not the original coder in this portion, I only assumed the work when my co-worker resigned.
Hope you can give a much clearer idea how i may do it.
Well, he told you to "check folder permissions" so... he probably thinks the error lies with the permissions of your folders.
$target_path = $target_path . basename( $_FILES['txt_file']['name']);
$_FILES['txt_file']['tmp_name']; // <-- What is the purpose of this line?
I was checking on the folder permissions, I don't find anything wrong with accessing the corresponding folder.
Im checking on your other suggestions.
The error message is the last error. "Could not copy file. Your file must be corrupted"
what are the permissions on the folder, just because you can access it via FTP doesn't mean the webserver has "write" permissions to it
taurus5_7 wrote:The error message is the last error. "Could not copy file. Your file must be corrupted"
Well, that's the user-generated error, yes. But if PHP is set to display all errors, it should have displayed an error when move_uploaded_file() failed. PHP's error messages are much more helpful when debugging.
ah alright! so that means I have to ask my webserver admin to "allow" writing on my sub-folders? Or is it the "permissions" I set in phpMyAdmin?
Ok, I will remove my "customized error message" then so I can view what is the error as interpreted by PHP, right? I will try doing so.
Thanks again
bradgrafelman wrote:Well, that's the user-generated error, yes. But if PHP is set to display all errors, it should have displayed an error when move_uploaded_file() failed. PHP's error messages are much more helpful when debugging.
I tried to echo the file name to check if it is POSTED properly by using
else {
echo("<div align=\"center\"><font class=\"blackHeader\">$target_path</font></div>");
and I find the result well after I added
<?php $saveto = $_POST["saveto"];//get action variable from browsefile ?>
at the start of the file, as suggested to declare it first. The file name as well as the extension is displayed as expected but of course the main problem remains.
So I did your suggestion to see what is the PHP error message. I tried using
else {
die("connection error ".mysql_error());
however it only displays the text "connection error". HOW CAN I MAKE THE PHP ERROR APPEAR?
I noticed from the code you posted in message 3 of this thread that you were using a mixture of short "<?" and long "<?php" tags. Depending on the php.ini settings, short tags are not allowed on some systems and this could be why it works on one but not on the other.
The other most likely possibility though, as Stolzy has already pointed out, is that the web server doesn't have either read or write permissions and thus may be either not writing the file to the default upload directory or not moving it to the requested directory.
HTH - Blu
Blulagoon wrote:I noticed from the code you posted in message 3 of this thread that you were using a mixture of short "<?" and long "<?php" tags. Depending on the php.ini settings, short tags are not allowed on some systems and this could be why it works on one but not on the other.
The other most likely possibility though, as Stolzy has already pointed out, is that the web server doesn't have either read or write permissions and thus may be either not writing the file to the default upload directory or not moving it to the requested directory.
HTH - Blu
Thanks. I tried "<?php" tag but it did not work out as well. So it must be the folder permission of my server. Is it privileges declared in mysql interface I use in my localhost? The server used in this project do not have a cpanel or mysql interface available, in that case I have to ask them directly to do it for me, right?
Is this a server you manage, or is it a shared server managed by a hosting company for you?
If the latter, you will need to ask the hosting company about the configuration. The hosting company I use in the UK don't allow me write access to the temp directory and this may be the case for you as well.
If this is the same for you, there is a work around which worked for me.
Blu
Blulagoon wrote:Is this a server you manage, or is it a shared server managed by a hosting company for you?
If the latter, you will need to ask the hosting company about the configuration. The hosting company I use in the UK don't allow me write access to the temp directory and this may be the case for you as well.
If this is the same for you, there is a work around which worked for me.
Blu
Thanks blu,
Indeed its not my own server. Can you share to me how it worked for you? should i write new code? or what?
And since we are already on the topic, what codes can I add it so that it will only accept specific file extensions or type such as jpg, gif, png or pdf?
Thanks again.
Buddy
if it's a *nix box, you can usually just FTP into the server, then chmod the folder in question to get the write permissions for it...
i'd get that step done before you go and change much more code
Sorry for my ignorance but - How to "CHMOD" the folder?
Taurus,
If you aren't able to change the permissions on the folder you need to, the alternative route to go down is this:
http://uk2.php.net/manual/en/ref.ftp.php
HTH - Blu
edit: On some windows ftp programs, right clicking on the remote folder will give you the chmod options if you are connected to a *nix server.
Bluelagoon wrote:if you are connected to a *nix server.
Even if it's a Windows server, the FTP server should have ported the CHMOD-style permissions feature... if not, it's a pretty lame server.
Thanks a lot guys.
I indeed tried modifying the write permissions of CHMOD and the currect server restricts modifying it. I have already requested the server admin to allow me modify folder permissions, but still waiting for the response... for almost 24 hours already.
I tried it in my other (2nd) hosting provider (over windows ftp program for both) and it allowed CHMOD modifications.
Im thinking of transferring the site to the second server providing my hosting requirements, but my concern is... it might affect the statistics of my sight. I mean, if I transfer it to another server, all previous statistics and Search Engine ranking will be removed/affected right?