1

Following is my code. It works perfectly well on local host. Somehow when I upload it on server image does not get save.

index.php:

<!doctype html>
<html lang="en">
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <title>Simple Capture Web camera image </title>
   <style type="text/css">
      body { font-family: Helvetica, sans-serif; }
      h2, h3 { margin-top:0; }
      form { margin-top: 16px; }
      form > input { margin-right: 16px; }
      #img_output { float:right; margin:21px; padding:21px; border:1px solid; background:#3d3d3d; }
   </style>
</head>
<body>
    
   <div id="img_output">Live captured image will Display here...</div>
   
   <h1>jQuery Capture Web camera image </h1>
   <h3>Live Demo And Example Demonstrates simple Images 600x460 capture & display here</h3>
   
   <div id="live_camera"></div>
   
   
   <script type="text/javascript" src="webcam.js"></script>
   
   
   <script language="JavaScript">
      Webcam.set({
         width: 600,
         height: 460,
         image_format: 'jpeg',
         jpeg_quality: 90
      });
      Webcam.attach( '#live_camera' );
   </script>
   
   
   <form>
      <input type=button value="Take Snapshot" onClick="get_take_snap()">
   </form>
   
   
   <script language="JavaScript">
      function get_take_snap() {
         // Simple call the take some your selfi and some get your live image data
         Webcam.snap( function(data_uri) {
            // display img_output in page
            
               
            Webcam.upload( data_uri, 'storeImage.php', function(code, text) {
               document.getElementById('img_output').innerHTML = 
               '<h2>Here is your Display image:</h2>' + 
               '<img src="'+text+'"/>';
            } );   
         } );
      }
   </script>
   
</body>
</html>

PHP Code

<?php
$myfilename =  time() . '.jpg';
$livefilepath = 'upload/';
move_uploaded_file($_FILES['webcam']['tmp_name'], $livefilepath.$myfilename);
echo $livefilepath.$myfilename;
?>
ADyson
  • 57,178
  • 14
  • 51
  • 63
Sourabh Potnis
  • 312
  • 1
  • 3
  • 11
  • 2
    What output do you get from PHP? Do you get any errors? Do you have error reporting or logging switched on in the server's PHP config? If so, did you check the error log file? (I ask because your question doesn't give any information about how you tried to investigate the problem.). Normally the most likely reasons for code which works to save a file in one environment but not another is either that the path doesn't exist, or that PHP/Apache doesn't have permission to write to that path. More than likely you have got an error message if you go and look at the log. – ADyson Oct 07 '20 at 07:42
  • @ADyson The error is as follows: The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. 404 (Not Found) – Sourabh Potnis Oct 07 '20 at 07:46
  • Is that seen in your browser's console when you try to make a request to `storeImage.php`? or you see it somewhere else? Please give full clarity. Either way, do you know what a 404 error means? Basically, there's a file which your browser tried to request, which is either missing from your server, or is in the wrong place (or, the link to it is wrong). It would help if you could explain which URL was being requested by the browser when that error occurred. Was it index.php? Or storeImage.php? Or the path returned by PHP and being used in the `img src`? – ADyson Oct 07 '20 at 07:58
  • @ADyson It is seen in console network. The path to save the image is perfect. It is in the server. The link given to it is right. The error occurs on path returned by PHP and image is not stored in the folder. storeImage.php shows the name of image saved only. – Sourabh Potnis Oct 07 '20 at 08:06
  • If the image isn't being stored, then go back to my first comment. Have you looked in the PHP error log file on the server, to see if any errors / warnings have been recorded during the save process? – ADyson Oct 07 '20 at 08:12
  • Also you aren't checking the return value of `move_uploaded_file()`. As per the manual (https://www.php.net/manual/en/function.move-uploaded-file.php): `Return Values : Returns TRUE on success. If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE. If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return FALSE. Additionally, a warning will be issued.` – ADyson Oct 07 '20 at 08:16
  • @ADyson Issue got resolved. It was due to permissions blocked. Hosting provider Admin server changed the permissions. – Sourabh Potnis Oct 07 '20 at 09:52
  • Ok that's good. If you have a specific solution you can write an Answer below - [it's fine to answer your own question](https://stackoverflow.com/help/self-answer), if you think it might be useful to others with similar issues in future. If you don't think it's useful to anyone then it's more appropriate to just delete the question. Thanks. – ADyson Oct 07 '20 at 10:08

1 Answers1

2

The Hosting Provider's Server Admin Team resolved the issue. A complete permission fix from the backend was done for this, so that all the permissions are fixed including the root directory.

Sourabh Potnis
  • 312
  • 1
  • 3
  • 11