Results 1 to 10 of 10

Thread: PHP Photo Album and iPhone

  1. #1
    Join Date
    Sep 2013
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default PHP Photo Album and iPhone

    I am using PHP Photo Album on a website I created for my granddaughter and am very happy.
    I also found a script that will upload images to my Photo Album folder from a smart phone.
    That worked great while I had a Droid phone.
    I switched to to an iPhone and find that Apple gives all outgoing images the same file name (image.jpg) therefore overwriting the last image.

    Is it possible to add code that would add unique two digits to each file name.

    image01.jpg, image02.jpg

    Thank you

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Is this for a DD script? If so, a moderator can move it to the appropriate forum.
    And also, then see this thread for the appropriate format:
    http://www.dynamicdrive.com/forums/s...-question-here

    Please:
    1. Include a link to the script.
    2. Include a link to your page to show us how it differs from the defaults and how it could be changed as required.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    As far as I can tell, this has nothing to do with the PHP Photo Album script, rather with file uploads. I find it hard to believe that the iphone cannot upload any image file other than image.jpg. Have you tried renaming the file before uploading it?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Actually, the iPhone's file system is incredibly stupid. Believe it. This has to do with Apple trying to make it "user friendly" (=automation with no control) and restrict access to the file system (you must jailbreak an iPhone to access files or use it as an external drive with a computer). Instead, everything is stored within Apps-- music within iTunes, recordings within Voice Memos, images within Photos, text notes within Notes, etc. And you CANNOT save any files from the internet (except for images as Photos). For example, you can't store a PDF on your phone (from the internet, from your computer, whatever).
    [I'm basing my knowledge on my now outdated iPhone 3GS, but as far as I know none of these fundamental aspects have changed.]

    So, no, I don't think there's any workaround from within the iPhone.

    Yes, in theory you can certainly alter the filename of an image when it is received by the server. But that's something that is part of the uploading script (and unrelated to the album as John said above). So your "script that will upload images to my Photo Album folder from a smart phone" [please specify which one!] would need to be changed. How would depend on the details of that script.
    The only other (awkward option) would be a cron job (automatically-repeating time-based operation) script on the server that would, for example, check for files named "image.jpg" every 5 minutes and automatically rename them. But this would be awkward (in addition to not being particularly easy to write if you haven't done it before) and wouldn't actually solve the problem if you uploaded more than one within 5 minutes [or whatever timeframe you set].

    I would recommend trying to alter the upload script, which shouldn't be all that difficult-- just append, for example, the date+time to the end of the filename.

    --
    Note: sorry for not realizing this earlier; based on our replies, it seems to that this is NOT actually about a DD script, just peripheral to one, so it really is a PHP question. But we'll still need to see the PHP script in order to help at all. (In this case a link to the page doesn't help-- PHP code is hidden. We'll need a link to where the code is available for download, or you could post it here in the thread.)
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Sep 2013
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Thanks for your response.
    You are correct. I don't think this is a DD script issue.
    The script is working exactly as designed and John has been very helpful in the past assisting me with reading the EXIF data.

    My knowledge of code is limited to inserting other peoples code into my website and making minor changes so I was just looking for direction.

    FYI
    What I understand from the iPhone support forums is that Apple saves images in a database as opposed to individual jpg files. When an image is emailed it is named photo.jpg and when uploaded image.jpg. If multiple images are sent in one email it calls them photo 1.jpg, photo 2.jpg etc,etc.

    One solution is to simply send them to my PC, change the name then upload. Since more pictures are taken with smart phones just thought it would be nice to send the right to the webpage.

    I will reach out to the upload script people ( ES Simple Uploader ) and see if they can make a change.

    These are the files.

    Config.php

    PHP Code:
    <?
    /*
    Upload dirs(folders) list
    - - - - - - - - - - - - - - - - - -
      "images" => array(
          "dir"     =>"uploads/images",
          "password"=>"images",
      ),
    - - - - - - - - - - - - - - - - - -
    "images" - just section name (any name you like), it is a key
    "name" - the dir(folder) name in select box
    "dir" - path to uploaded files
    "password" - "dir" password
    */
    $upload_dirs = array(
      
    "images" => array(
          
    "dir"     =>"uploads/images/",
          
    "name"    =>"Images folder",
          
    "password"=>"images",
      ),
      
    "docs" => array(
          
    "dir"     =>"uploads/docs/",
          
    "name"    =>"Docs",
          
    "password"=>"docs",
      ),
      
    "common" => array(
          
    "dir"     =>"uploads/common/",
          
    "name"    =>"Common files",
          
    "password"=>"common",
      ),
    );

    $max_file_size 500000*1024//max file upload size (bytes)
    ?>

    Index.php

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>
      <title>ES Simple Uploader</title>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      <meta name="generator" content="handmade" />
        <style type="text/css">
        <!--
            body {
                font-family: Arial, Helvetica, sans-serif;
                font-size: 14px;
                background-color: #DDDDDD;
            }
            .cnt {
                text-align: center;
            }
            .cnt_welcome {
                font-size: 16px;
                font-weight: bold;
                text-align: center;
            }
            .cnt_powered {
                font-size: 14px;
                font-weight: bold;
                text-align: center;
            }
            .cnt_small {
                font-size: 12px;
                text-align: center;
                padding-top: 50px;
            }
            .head_line {
                background-color: #BBBBBB;
            }
            .main_table {
                border: solid 1px #9D9992;
                font-size: 13px;
            }
            h4 {
                font-size: 12px;
                color: #DD0000;
                text-align: center;
            }
            .button {
                border: 1px solid #55555;
                font-weight: bold;
            }
    -->
    </style>
    </head>

    <body>
    <?
    include("config.php");

    function 
    path_options()
    {
     global 
    $upload_dirs;
      
    $option "";
      foreach (
    $upload_dirs as $path => $pinfo)
      {
        
    $option .= '<option value="'.$path.'">'.$pinfo["name"].'</option>';
      }
     return 
    $option;
    }

    function 
    check_vals()
    {
     global 
    $upload_dirs$err;
        if (!
    ini_get("file_uploads")) { $err .= "HTTP file uploading is blocked in php configuration file (php.ini). Please, contact to server administrator."; return 0; }
        
    $pos strpos(ini_get("disable_functions"), "move_uploaded_file");
        if (
    $pos !== false) { $err .= "PHP function move_uploaded_file is blocked in php configuration file (php.ini). Please, contact to server administrator."; return 0; }
      if (!isset(
    $_POST["path"]) || (strlen($_POST["path"]) == 0)) { $err .= "Please fill out path"; return 0; }
      if (!isset(
    $upload_dirs[$_POST["path"]])) { $err .= "Incorrect path"; return 0; }
      if (!isset(
    $_POST["pwd"]) || (strlen($_POST["pwd"]) == 0)) { $err .= "Please fill out password"; return 0; }
      elseif (
    $_POST["pwd"] != $upload_dirs[$_POST["path"]]["password"]) { $err .= "The upload password is incorrect"; return 0; }
      if (!isset(
    $_FILES["userfile"])) { $err .= "Empty file"; return 0; }
      elseif (!
    is_uploaded_file($_FILES['userfile']['tmp_name'])) { $err .= "Empty file"; return 0; }
     return 
    1;
    }

    $err ""$status 0;
    if (isset(
    $_POST["upload"])) {
      if (
    check_vals()) {
        if (
    filesize($_FILES["userfile"]["tmp_name"]) > $max_file_size$err .= "Maximum file size limit: $max_file_size bytes";
        else {
          if (
    move_uploaded_file($_FILES["userfile"]["tmp_name"], $upload_dirs[$_POST["path"]]["dir"].$_FILES["userfile"]["name"])) {
                    
    $status 1;
                }
          else 
    $err .= "There are some errors!";
        }
      }
    }

    if (!
    $status) {
      if (
    strlen($err) > 0) echo "<h4>$err</h4>";
    }
    else {
      echo 
    "<h4>&quot;".$_FILES["userfile"]["name"]."&quot; was successfully uploaded.</h4>";
    }
    ?>
    <p class="cnt_welcome">Welcome to ES Simple Uploader v 1.1.</p>
    <p class="cnt">&laquo; <a href="http://www.energyscripts.com/Products/product2.html">Back to Product page</a> &laquo;</p>
    <p class="cnt">(Select folder, set it's password, then select a file to upload and click "Upload" button).
        <br />Note: 
            Folder: &quot;Images folder&quot;, Password: &quot;images&quot;;
            Folder: &quot;Docs&quot;, Password: &quot;docs&quot;;
            Folder: &quot;Common files&quot;, Password: &quot;common&quot;;
            Maximum file size: <?=$max_file_size/1024?> Kb.</p><br />
    <form enctype="multipart/form-data" action="index.php" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="<?=$max_file_size?>" />
    <table class="main_table" align="center">
      <tr>
        <td colspan="2" class="head_line">&nbsp;</td>
      </tr>
      <tr>
        <td>Folder:</td>
        <td><select name="path"><?=path_options()?></select></td>
      </tr>
      <tr>
        <td>Password:</td>
        <td><input type="password" name="pwd" style="width: 217px;" /></td>
      </tr>
      <tr>
        <td>Choose file:</td>
        <td><input type="file" name="userfile" style="width: 222px;" /></td>
      </tr>
      <tr>
        <td colspan="2" align="right"><input type="submit" name="upload" value="Upload" class="button" /></td>
      </tr>
    </table>
    </form>
    </p>
    <p class="cnt_powered">Powered by <a href="http://www.energyscripts.com" target="_blank">EnergyScripts</a></p>
    <p class="cnt_small">Find more power solution: <a href="http://www.energyscripts.com/Products/product1.html" target="_blank">ES File Upload &amp; Download Manager</a></p>
    </body>
    </html>
    Last edited by jscheuer1; 11-20-2013 at 01:43 PM. Reason: Format

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The code you posted doesn't contain the filename part. We'll need index.php (from the zip file at the link you posted).

    Here's the relevant section:
    PHP Code:
    $err ""$status 0;
    if (isset(
    $_POST["upload"])) {
      if (
    check_vals()) {
        if (
    filesize($_FILES["userfile"]["tmp_name"]) > $max_file_size$err .= "Maximum file size limit: $max_file_size bytes";
        else {
          if (
    move_uploaded_file($_FILES["userfile"]["tmp_name"], $upload_dirs[$_POST["path"]]["dir"].$_FILES["userfile"]["name"])) {
                    
    $status 1;
                }
          else 
    $err .= "There are some errors!";
        }
      }

    The line that matters:
    PHP Code:
          if (move_uploaded_file($_FILES["userfile"]["tmp_name"], $upload_dirs[$_POST["path"]]["dir"].$_FILES["userfile"]["name"])) { 
    As you can see, it just takes the name from "userfile", as sent from the user.

    So there are a few options. How exactly do you want it renamed and in what conditions?

    1. If it's exactly "image.jpg", rename to "image[DATE].jpg".
    2. Always add some ending, like "filename[DATE].jpg".
    3. If a file exists with that name, then add a sequential number to the end of ANY upload.

    Option 3 is perhaps the best but also a little complicated.


    I can help you with this probably. Which one (or some other option) do you want?
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Sep 2013
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    This link is to a sample file upload page I setup.
    http://b-j.com/esuploader/index.php

    It will upload any images chosen to a folder on my server and display them in a DD Photo Album.
    This can be run from a PC or also accessed through the web browser of the iPhone. When a picture is "chosen" from the Camera Roll of the iPhone, any and all images are sent, read or recognized as "image.jpg".

    I would like the renaming option to be:
    If it's exactly "image.jpg", rename to "image[DATE,TIME].jpg" anything else leave as is.
    My reason is that there could be multiple uploads on any given day but highly unlikely at the same time.

    This link is to the page displaying the results of the uploads using DD PHP Photo Album script v2.11
    http://b-j.com/photos.html



    The following is the actual index.php for the upload script.

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>
    
    
      <title>ES Simple Uploader</title>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      <meta name="generator" content="handmade" />
    	<style type="text/css">
    	<!--
    		body {
    			font-family: Arial, Helvetica, sans-serif;
    			font-size: 14px;
    			background-color: #DDDDDD;
    		}
    		.cnt {
    			text-align: center;
    		}
    		.cnt_welcome {
    			font-size: 16px;
    			font-weight: bold;
    			text-align: center;
    		}
    		.cnt_powered {
    			font-size: 14px;
    			font-weight: bold;
    			text-align: center;
    		}
    		.cnt_small {
    			font-size: 12px;
    			text-align: center;
    			padding-top: 50px;
    		}
    		.head_line {
    			background-color: #BBBBBB;
    		}
    		.main_table {
    			border: solid 1px #9D9992;
    			font-size: 13px;
    		}
    		h4 {
    			font-size: 12px;
    			color: #DD0000;
    			text-align: center;
    		}
    		.button {
    			border: 1px solid #55555;
    			font-weight: bold;
    		}
    -->
    </style>
    
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    </head>
    
    <body>
    
    <?
    include("config.php");
    
    function path_options()
    {
     global $upload_dirs;
      $option = "";
      foreach ($upload_dirs as $path => $pinfo)
      {
        $option .= '<option value="'.$path.'">'.$pinfo["name"].'</option>';
      }
     return $option;
    }
    
    function check_vals()
    {
     global $upload_dirs, $err;
     
    	if (!ini_get("file_uploads")) { $err .= "HTTP file uploading is blocked in php configuration file (php.ini). Please, contact to server administrator."; return 0; }
    	$pos = strpos(ini_get("disable_functions"), "move_uploaded_file");
    	if ($pos !== false) { $err .= "PHP function move_uploaded_file is blocked in php configuration file (php.ini). Please, contact to server administrator."; return 0; }
      if (!isset($_POST["path"]) || (strlen($_POST["path"]) == 0)) { $err .= "Please fill out path"; return 0; }
      if (!isset($upload_dirs[$_POST["path"]])) { $err .= "Incorrect path"; return 0; }
      if (!isset($_POST["pwd"]) || (strlen($_POST["pwd"]) == 0)) { $err .= "Please fill out password"; return 0; }
      elseif ($_POST["pwd"] != $upload_dirs[$_POST["path"]]["password"]) { $err .= "The upload password is incorrect"; return 0; }
      if (!isset($_FILES["userfile"])) { $err .= "Empty file"; return 0; }
      elseif (!is_uploaded_file($_FILES['userfile']['tmp_name'])) { $err .= "Empty file"; return 0; }
     return 1;
    }
    
    $err = ""; $status = 0;
    if (isset($_POST["upload"])) {
      if (check_vals()) {
        if (filesize($_FILES["userfile"]["tmp_name"]) > $max_file_size) $err .= "Maximum file size limit: $max_file_size bytes";
        else {
          if (move_uploaded_file($_FILES["userfile"]["tmp_name"], $upload_dirs[$_POST["path"]]["dir"].$_FILES["userfile"]["name"])) {
    				$status = 1;
    			}
          else $err .= "There are some errors!";
        }
      }
    }
    
    if (!$status) {
      if (strlen($err) > 0) echo "<h4>$err</h4>";
    }
    else {
      echo "<h4>&quot;".$_FILES["userfile"]["name"]."&quot; was successfully uploaded.</h4>";
    }
    
    ?>
    <p class="cnt_welcome">Upload Your Image Here</p>
    <p class="cnt">Enter the password<br />
    &nbsp;then select an image to upload<br />
    and click the "Upload" button).
    	<br /></p>
    <br />
    <form enctype="multipart/form-data" action="index.php" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="<?=$max_file_size?>" />
    <table class="main_table" align="center">
      <tr>
        <td colspan="2" class="head_line">&nbsp;</td>
      </tr>
      <tr>
        <td>Folder:</td>
        <td><select name="path"><?=path_options()?></select></td>
      </tr>
      <tr>
        <td>Password:</td>
        <td><input type="password" name="pwd" style="width: 217px;" /></td>
      </tr>
      <tr>
        <td>Choose file:</td>
        <td><input type="file" name="userfile" style="width: 222px;" /></td>
      </tr>
      <tr>
        <td colspan="2" align="right"><input type="submit" name="upload" value="Upload" class="button" /></td>
      </tr>
    </table>
    </form>
    </p>
    <p class="cnt_powered">Powered by <a href="" target="_blank"></a></p>
    </body>
    </html>
    Last edited by keyboard; 11-21-2013 at 08:01 AM. Reason: Format: Html Tags [html][/html]

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Ok, so here's how to do that:

    Find this:
    PHP Code:
    if (move_uploaded_file($_FILES["userfile"]["tmp_name"], $upload_dirs[$_POST["path"]]["dir"].$_FILES["userfile"]["name"])) {
    $status 1;

    Replace with this:
    PHP Code:
    $uploadname $_FILES["userfile"]["name"]; //get the original filename
    if ($uploadname == 'image.jpg') { //if it's just "image.jpg"
         
    $uploadname 'image-'.time().'.jpg'//append the current timestamp [seconds since 1970]
    }
    if (
    move_uploaded_file($_FILES["userfile"]["tmp_name"], $upload_dirs[$_POST["path"]]["dir"].$uploadname)) {
    $status 1;

    All relatively simple. It should work fine, though of course I haven't tested it, so play with it a bit.
    Note that it would be easy to change this from date+time to something else, such as including the user's IP address so if two users do upload at the same second they'd still be distinct. It sort of depends on how long you want the filenames to be.
    Alternatively you could generate a code by combining several types of information [this process is known as "hashing" and it's very easy with a function like md5(_string_)].
    But for now, this should solve your immediate problems and be enough.

    There's one potential security issue here: by allowing the user to name their own files, you are potentially allowing them to do something weird with the filename-- odd file extension, or perhaps include a directory in it so they can access a part of the server where they shouldn't be. I'm not positive how PHP handles file uploads-- it might automatically strip bad/dangerous data from the "filename" part, but I'm not sure about this.
    Generally speaking, I always rename files when I upload them, usually based on the time, username, or something else.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Sep 2013
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Cannot try this until tomorrow but will keep you posted.
    Thanks

  10. #10
    Join Date
    Sep 2013
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Thank you very much.
    It works perfectly.
    Thanks again!!!!

Similar Threads

  1. PHP Photo Album Help
    By doublesnaggle in forum Dynamic Drive scripts help
    Replies: 3
    Last Post: 02-25-2012, 01:28 AM
  2. PHP photo album 2.0
    By moose86 in forum Dynamic Drive scripts help
    Replies: 5
    Last Post: 12-12-2011, 01:06 AM
  3. Add Photo Title to PHP Photo Album Script
    By EdgeAgain in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 09-27-2009, 11:31 PM
  4. facebook photo (iPhone)
    By queerfm in forum Looking for such a script or service
    Replies: 3
    Last Post: 03-09-2008, 07:43 AM
  5. DD PHP Photo Album script - photo descrip
    By aavaughan in forum Dynamic Drive scripts help
    Replies: 4
    Last Post: 09-13-2007, 12:44 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •