b_kitty Posted February 9, 2007 Share Posted February 9, 2007 I have a script that allows file upload. It seems like it works when i use it in my local webserver but when the scripts are transfered in a different web server, it does no long work. I think this my be a path problem, maybe something wrong with my $archive_dir value! Is there any rule on this value????? Or maybe there is something wrong with the webserver itself?! :-\ I really Hope someone could Help..!! Quote Link to comment Share on other sites More sharing options...
camdagr81 Posted February 9, 2007 Share Posted February 9, 2007 Check the permissions of the folder you are saving the file to. Make sure that it is writeable. Also check the max upload size. You maybe exceeding your limit. Quote Link to comment Share on other sites More sharing options...
b_kitty Posted February 9, 2007 Author Share Posted February 9, 2007 i checked the permission...I made them 777 ..but nothing happens Also the max size seems to be OK! ??? Quote Link to comment Share on other sites More sharing options...
camdagr81 Posted February 9, 2007 Share Posted February 9, 2007 are you copying the file to a directory? What does your upload script look like? function upload_copy_file() { if (is_uploaded_file($_FILES['file']['tmp_name'])) { $file = $_FILES['file']['name']; $path = '/uploads/' . $file; if (copy($_FILES['file']['tmp_name'], $path)) { return 1; } else { return 2; } } else { return 3; } } Quote Link to comment Share on other sites More sharing options...
b_kitty Posted February 9, 2007 Author Share Posted February 9, 2007 yes, i am copping the files in a directoy on the web server. My upload script is: function upload_file() { global $userfile, $userfile_name, $userfile_size, $userfile_type, $archive_dir, $WINDIR; if(isset($WINDIR)) $userfile = str_replace("\\\\","\\", $userfile); $filename = basename($userfile_name); if($userfile_size <= 0) die ("$filename is empty."); if(!@copy($userfile, "$archive_dir/$filename")) die("Nuk mund të kopjojë $userfile_name tek $filename."); //if(isset(!$WINDIR) && !@unlink($userfile)) //die ("Can't delete the file $userfile_name."); echo "Imazhi $filename u upload-ua me sukses.<BR>"; echo "<a href=mod_imazhe.php>Klioni ketu per te bere upload nje imazh tjeter</a>" ;} Quote Link to comment Share on other sites More sharing options...
camdagr81 Posted February 9, 2007 Share Posted February 9, 2007 try using / instead of \\ Quote Link to comment Share on other sites More sharing options...
b_kitty Posted February 9, 2007 Author Share Posted February 9, 2007 It didn't work Anyway...can i use a path like this $archive_dir = "../../Index/imazhe";???? Quote Link to comment Share on other sites More sharing options...
camdagr81 Posted February 9, 2007 Share Posted February 9, 2007 you should be able to, is your script checking for is_uploaded_file() anywhere? That will tell you if the file is even being uploaded to your host. Quote Link to comment Share on other sites More sharing options...
b_kitty Posted February 9, 2007 Author Share Posted February 9, 2007 mmmmmmmm...no. But i am checking it from my FTP and no upload is happening! Maybe i should ask for the appache and php configuration files to be checked ??? By the way...thank you for your help and replys Quote Link to comment Share on other sites More sharing options...
camdagr81 Posted February 9, 2007 Share Posted February 9, 2007 No problem I'm sure the problem is that you're not copying the file from the temp directory of the host. If you take a look at the upload_copy_file() function i posted here above, you can see how it takes the http post info and determines if the file has been uploaded. Also, in your upload form, do you have the: enctype="multipart/form-data" tag included? The file will not send to the server if it isn't present. If you want, i can take a look at your entire script and try to debug it for you (I'm avoiding doing my own work at the moment.. teehee). Quote Link to comment Share on other sites More sharing options...
b_kitty Posted February 9, 2007 Author Share Posted February 9, 2007 Ok...i am attaching it...but i am new in designing web - pages so don't get scared when you'll see my strange code lines [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
camdagr81 Posted February 9, 2007 Share Posted February 9, 2007 Try using this as your upload function: function upload_file() { // Check to see if the file has been uploaded to the server if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { // get the file name from the form and replace spaces with underscore '_' $userfile = str_replace(' ', '_', $_FILES['userfile']['name']); // Set the save to directory $saveto = '../../Index/imazhe/'; // Copy the file from the servers temp directory to your sites directory if (copy($_FILES['file']['tmp_name'], $saveto . $file)) { // If successful -> echo upload message and exit function echo "Imazhi $filename u upload-ua me sukses.<BR>"; return; } // If unable to copy send error message and exit the function else { echo "Nuk mund të kopjojë $userfile_name tek $userfile."; return; } }// end if_uploaded_file(); // Send Error message if unable to upload file else { echo "ERROR UPLOADING FILE"; return; } }// end upload_file() Sorry it took me so long to get back to you, I needed to eat Quote Link to comment Share on other sites More sharing options...
camdagr81 Posted February 9, 2007 Share Posted February 9, 2007 oops light error :-\ Try using this as your upload function: function upload_file() { // Check to see if the file has been uploaded to the server if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { // get the file name from the form and replace spaces with underscore '_' $file = str_replace(' ', '_', $_FILES['userfile']['name']); // Set the save to directory $saveto = '../../Index/imazhe/'; // Copy the file from the servers temp directory to your sites directory if (copy($_FILES['file']['tmp_name'], $saveto . $file)) { // If successful -> echo upload message and exit function echo "Imazhi $filename u upload-ua me sukses.<BR>"; return; } // If unable to copy send error message and exit the function else { echo "Nuk mund të kopjojë $userfile_name tek $file."; return; } }// end if_uploaded_file(); // Send Error message if unable to upload file else { echo "ERROR UPLOADING FILE"; return; } }// end upload_file() Sorry it took me so long to get back to you, I needed to eat Quote Link to comment Share on other sites More sharing options...
b_kitty Posted February 11, 2007 Author Share Posted February 11, 2007 sorry i couldn't reply immediately...but anyway, it didn't work :'( Anny other idea ?? Quote Link to comment Share on other sites More sharing options...
camdagr81 Posted February 14, 2007 Share Posted February 14, 2007 Hmmm not sure why it won't work for you. Maybe something server related then. Quote Link to comment Share on other sites More sharing options...
TheOne17 Posted February 14, 2007 Share Posted February 14, 2007 Is the server a Windows box or Linux? If it is Windows I'm pretty sure you can't change permissions via FTP. BTW there is FTP functions in PHP, you upload via FTP using PHP Quote Link to comment Share on other sites More sharing options...
b_kitty Posted February 15, 2007 Author Share Posted February 15, 2007 It is a LINUX server. I tried the script in XAMPP environment and it worked! But it doesn't where it should...in the LINUX server Anyway, for security reasons, the hosting guys dont allow ftp for any user..only internal users, so i need the browser version of upload for the users to upload from anywhere! Quote Link to comment 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.