emldesign Posted March 1, 2011 Share Posted March 1, 2011 Hello all, I have a script uploading files on the server. I would like to send a confirmation to user if the file had been uploaded well. $targetFile = str_replace('//','/',$targetPath) . $filename; move_uploaded_file($tempFile,$targetFile); if (str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile)) { mail($to, 'upload notification', "Dear Mr/Mrs $fixedname, the file entitled $filename has been successfully uploaded"); }else { mail($to, ' upload notification', "Dear Mr/Mrs $fixedname, the file entitled $filename has been NOT uploaded"); } I presume I do something wrong because it doesn't work. The successfull email is sent each time. Thank you very much for helping, Eric Quote Link to comment Share on other sites More sharing options...
KPH71 Posted March 1, 2011 Share Posted March 1, 2011 With this line: if (str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile)) you are determining whether the file has been uploaded - however this function seems irrelevant to the upload (it will return a value if it can fine '' in the document root). Can I suggest something like: if (file_exists($targetFile)) instead - i.e. checking to see if that file is now on the server. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted March 1, 2011 Share Posted March 1, 2011 Because the string replace is always successful I assume. Try: if (move_uploaded_file($tempFile,$targetFile)) Quote Link to comment Share on other sites More sharing options...
emldesign Posted March 1, 2011 Author Share Posted March 1, 2011 hi thank you for helping. I did : if (move_uploaded_file($tempFile,$targetFile)){ str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile); mail($to, 'Upload notification', "Dear Mr/Mrs $fixedname, the file entitled $filename has been successfully uploaded on our servers."); }else { mail($to, 'Upload notification', "Dear Mr/Mrs $fixedname, the file entitled $filename has been NOT successfully uploaded on our servers. !!!!!"); } This time nothing works any more. Here is a link to the page: http://www.emldesign.be/test/physphar/ Thank you Quote Link to comment Share on other sites More sharing options...
emldesign Posted March 1, 2011 Author Share Posted March 1, 2011 Thank you AbraAadaver move_uploaded_file($tempFile,$targetFile); str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile); if (file_exists($targetFile)){ mail($to, 'Upload notification', "Dear Mr/Mrs $fixedname, the file entitled $filename has been successfully uploaded on our servers."); }else { mail($to, 'Upload notification', "Dear Mr/Mrs $fixedname, the file entitled $filename has been NOT successfully uploaded on our servers!"); } There is still something wrong because the progress bar stop suddenly before 100%. Thank you Quote Link to comment Share on other sites More sharing options...
MikeDean89 Posted March 1, 2011 Share Posted March 1, 2011 You really shouldn't worry about the str_replace, it's not doing anything any more. Also, using the file_exists function is pretty pointless here. if (move_uploaded_file($tempFile,$targetFile)){ mail($to, 'Upload notification', "Dear Mr/Mrs $fixedname, the file entitled $filename has been successfully uploaded on our servers."); }else { mail($to, 'Upload notification', "Dear Mr/Mrs $fixedname, the file entitled $filename has been NOT successfully uploaded on our servers!"); } Give that a go and let us know your results. Quote Link to comment Share on other sites More sharing options...
emldesign Posted March 1, 2011 Author Share Posted March 1, 2011 Hello ! BETTER: This time uploading works but I received the wrong mail : Dear Mr/Mrs test3, the file entitled physphar_test3_iPhone_intro_1299001253.pdf has been NOT successfully uploaded on our servers! Even if the file "physphar_test3_iPhone_intro_1299001253.pdf" is on the server actually.... :s $targetFile = str_replace('//','/',$targetPath) . $filename; move_uploaded_file($tempFile,$targetFile); str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile); if (move_uploaded_file($tempFile,$targetFile)){ mail($to, 'Upload notification', "Dear Mr/Mrs $fixedname, the file entitled $filename has been successfully uploaded on our servers."); }else { mail($to, 'Upload notification', "Dear Mr/Mrs $fixedname, the file entitled $filename has been NOT successfully uploaded on our servers!"); } Quote Link to comment Share on other sites More sharing options...
MikeDean89 Posted March 1, 2011 Share Posted March 1, 2011 Because you've already uploaded the file, the temp file will no longer be available (as you've moved it) - use the code below: $targetFile = str_replace('//','/',$targetPath) . $filename; if (move_uploaded_file($tempFile,$targetFile)){ mail($to, 'Upload notification', "Dear Mr/Mrs $fixedname, the file entitled $filename has been successfully uploaded on our servers."); }else { mail($to, 'Upload notification', "Dear Mr/Mrs $fixedname, the file entitled $filename has been NOT successfully uploaded on our servers!"); } Quote Link to comment Share on other sites More sharing options...
emldesign Posted March 1, 2011 Author Share Posted March 1, 2011 Ho Yes it works PERFECTLY ! To all > Thank you very much for helping ! Eric 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.