Jump to content

Automatically set file path.


isimpledesign
 Share

Recommended Posts

Hi

 

Everyone i am looking for a way to automatically upload a file but skip the browse and choose file process.

 

So i set the location of the file somehow via the form and the client just has to click submit and it will automatcially upload the file from the path i have set. skipping the browse for file process.

 

I would like to intergrate it into the following undesigns S3 Class

 

http://undesigned.org.za/2007/10/22/amazon-s3-php-class/documentation

 

<?php

    S3::setAuth(awsAccessKey, awsSecretKey);

    $bucket = "upload-bucket";
    $path = "myfiles/"; // Can be empty ""

    $lifetime = 3600; // Period for which the parameters are valid
    $maxFileSize = (1024 * 1024 * 50); // 50 MB

    $metaHeaders = array("uid" => 123);
    $requestHeaders = array(
        "Content-Type" => "application/octet-stream",
        "Content-Disposition" => 'attachment; filename=${filename}'
    );

    $params = S3::getHttpUploadPostParams(
        $bucket,
        $path,
        S3::ACL_PUBLIC_READ,
        $lifetime,
        $maxFileSize,
        201, // Or a URL to redirect to on success
        $metaHeaders,
        $requestHeaders,
        false // False since we're not using flash
    );

    $uploadURL = "https://{$bucket}.s3.amazonaws.com/";

?><!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" xml:lang="en" lang="en">
<head>
    <title>S3 Form Upload</title>
</head>
<body>
    <form method="post" action="<?php echo $uploadURL; ?>" enctype="multipart/form-data">
<?php
    foreach ($params as $p => $v)
        echo "        <input type=\"hidden\" name=\"{$p}\" value=\"{$v}\" />\n";
?>
        <input type="file" name="file" />&#160;<input type="submit" value="Upload" />
    </form>
</body>
</html>

 

at what point does it grab the file path ?

 

is it grabbing it out of the name here

<input type="file" name="file" />

 

can i do something with $_FILES ???

 

Can someone please give me a point on where to start i would really appriciate this.

 

thanks

 

Link to comment
Share on other sites

I have just read this

 

http://www.phpfreaks.com/forums/php-coding-help/set-file-path/

 

So i thinks its not possible.

 

but i dont want it to download off someone comupter but from their server root.

 

Basically do a backup zip it and the set the path for that to be uploaded so all the user has to do is click upload, because i will set the path to the file???

Link to comment
Share on other sites

 

That doesnt seem to work

 

<input type="file" name="file" value="/Users/SamuelEast/Desktop/businesscard.psd" /><input type="submit" value="Upload" />

 

just gives me an error.

 

<Error>

<Code>InvalidArgument</Code>

<Message>User key must have a length greater than 0.</Message>

<ArgumentValue/>

<ArgumentName>key</ArgumentName>

</Error>

Link to comment
Share on other sites

You cannot do this for the simple reason that it's different for everyone.  Take your desktop into account for example.  Most likely, you're running windows, so you got something like C:\Username\Desktop .. or atleast close to that, while I'm on Ubuntu and have /home/icexaos/Desktop.

 

Besides the fact that they're located with two completely different locations due to OS differences, 99.9% of all people will have different usernames which you cannot take into account.

 

If you wanted to make it Windows only, I do believe there's a path command to automatically use the Desktop, for example what "~/Desktop" would be in Linux.

 

I'm done rambling now.  Basically the point is, it's easier to just use a file browser and choose the file.

Link to comment
Share on other sites

 

Hi Kira

 

Thanks for the reply i want to grab the file from the server so i was looking at doing something like the follow.

 

so my file structure would be.

 

index.php // which would have the upload code

files/backup.zip //which would be the file i would like to automatically grab

 

so i thinking of doing something like

 

$_SERVER['DOCUMENT_ROOT']."/files/backup.zip

 

to locate the file?

Link to comment
Share on other sites

i can do something like this which shows the files but i get the error below

 

<?php
S3::setAuth(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY);



    $bucket = "bucket";
    $path = ""; // Can be empty ""

    $lifetime = 3600; // Period for which the parameters are valid
    $maxFileSize = (1024 * 1024 * 50); // 50 MB

    $metaHeaders = array("uid" => 123);
    $requestHeaders = array(
        "Content-Type" => "application/octet-stream",
        "Content-Disposition" => 'attachment; filename=${filename}'
    );

    $params = S3::getHttpUploadPostParams(
        $bucket,
        $path,
        S3::ACL_PUBLIC_READ,
        $lifetime,
        $maxFileSize,
        201, // Or a URL to redirect to on success
        $metaHeaders,
        $requestHeaders,
        false // False since we're not using flash
    );

    $uploadURL = "https://{$bucket}.s3.amazonaws.com/";

?><!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" xml:lang="en" lang="en">
<head>
    <title>S3 Form Upload</title>
</head>
<body>
    <form method="post" action="<?php echo $uploadURL; ?>" enctype="multipart/form-data">
<?php
    foreach ($params as $p => $v)
        echo "        <input type=\"hidden\" name=\"{$p}\" value=\"{$v}\" />\n";
?>
        <input type="text" name="file" value="<?php echo $_SERVER['DOCUMENT_ROOT']."/wp-content/plugins/s3allfiles/files/test.txt"; ?>" /><input type="submit" value="Upload" />
    </form>
</body>
</html>

 

so ichange the type to text instead of file

 

i get this error

 

<PostResponse>

<Location>

https://bucket.s3.amazonaws.com/%24%7Bfilename%7D

</Location>

<Bucket>bucket</Bucket>

<Key>${filename}</Key>

</PostResponse>

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.