Using php APC and ajax http call, my file upload progress bar works fine but here is my problem::

file is uploaded by submitting form to a script upload.php which simply moves the uploaded file from temp location to a specified location.

upload_form.php has one form that includes the info about uploading file but HERE IS MY COMPLICATION:: this file upload is just a part of my other form, where a user is posting an article, hence user info, email, article title, article body bla bla are also being submitted along with the file(image file)

Because I need to process other info (user info, article body etc) on server side script, I do not want to move the uploaded file to specified folder just yet because if the uer aborts the submission of his article this uploaded file is just a waste to keep in the folder.

My Question is how long is an uploaded file kept in the temp directory by the server? OR, what is the proper mechanism to submitting an article that includes a file upload as well??

any help would be appreciated, thanks

upload_form.php
(working fine)

<form onSubmit="startProgress('<?php echo $uid; ?>');" action="upload1.php" method="post" enctype="multipart/form-data" name="upload" id="upload" target="upload_frame">
<input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $uid; ?>" />
<input type="file" name="file" id="file" />
<input type="text" name="tt" id="text" value="text value" />
<input type="submit" name="submit" id="submit" value="Upload!" />
</form>

<div id="pb_outer">
<div id="pb_inner"></div>
</div>

upload.php

if($FILES['file']['error'] == UPLOAD_ERR_OK)
{
$tmp = explode(".", $
FILES["file"]["name"]);
$ext = $tmp[sizeof($tmp)-1];
$newFname = $POST['APC_UPLOAD_PROGRESS'] . "." . $ext;
$path = 'files/';
$path .= $newFname; //basename($
FILES['file']['name']);
if(move_uploaded_file($_FILES['file']['tmp_name'], $path))
{
// upload successful
echo "File uploaded\n";

}
}

getprogress.php
is called on by ajax httprequest to poll the uploaded amount of the file being uploaded,, which is displayed in upload_form page in 'pb_inner' div.

    because its hard to work with and handle the php garbage collector(that deletes the temp files) i would move the files to my own temp dir, move them to the finial location when i have finished processing the form and cron job delete my temp daily. moving files on a disk is a matter or renaming them, so its not very resource intensive.

    instead of 2 dirs you could use one and have some file name convention; like temp_file.jpg, rename to file.jpg for 'live' and delete temp_* every midnight

      According to the PHP manual:

      The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed.

        bad me, i thought the garbage collector did it 🙁

          dagon;10948162 wrote:

          because its hard to work with and handle the php garbage collector(that deletes the temp files) i would move the files to my own temp dir, move them to the finial location when i have finished processing the form and cron job delete my temp daily. moving files on a disk is a matter or renaming them, so its not very resource intensive.

          instead of 2 dirs you could use one and have some file name convention; like temp_file.jpg, rename to file.jpg for 'live' and delete temp_* every midnight

          Thanks for the tip. Basically you are suggesting move the file to a temp location of your own and when all the work is complete move to final destination folder? This would include having to delete the aborted submission files from your temp folder.

          I would like to know what is the convention to do this task, example::writing email in yahoo attaching a picture, how do they do it ?

          Any hint would be appreciated.
          thanks

            how do yahoo do it? wouldn't have a clue, ask them

              haha thanks dragon,

              I meant what would be more conventional way of doing it other than moving the file to temp location from temp and then moving again to a final destination.

              😃

                i don't know if theirs any convention, i don't know what the majority of php programmers would do in the same circumstance, i only know what i would do.

                  Write a Reply...