petersego
asked on
Can I use this formscript to auto-upload
My PHP-knowledge is extremely limited, so Im sorry if this is a stupid question.
I have a script that uploads files through a form. See snippet.
How do I change it to upload files in the same folder as the php-file - either through POST or GET.
I have a script that uploads files through a form. See snippet.
How do I change it to upload files in the same folder as the php-file - either through POST or GET.
<?php
//include the S3 class
if (!class_exists('S3'))require_once('S3.php');
//AWS access info
if (!defined('awsAccessKey')) define('awsAccessKey', 'XXXXXXXXXXXXXXX');
if (!defined('awsSecretKey')) define('awsSecretKey', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX');
//instantiate the class
$s3 = new S3(awsAccessKey, awsSecretKey);
//check whether a form was submitted
if(isset($_POST['Submit'])){
//retreive post variables
$fileName = $_FILES['theFile']['name'];
$fileTempName = $_FILES['theFile']['tmp_name'];
//create a new bucket
$s3->putBucket("yourbucket", S3::ACL_PUBLIC_READ);
//move the file
if ($s3->putObjectFile($fileTempName, "stepviz", $fileName, S3::ACL_PUBLIC_READ)) {
echo "<strong>We successfully uploaded your file.</strong>";
}else{
echo "<strong>Something went wrong while uploading your file... sorry.</strong>";
}
}
?>
<h1>Upload a file</h1>
<p>Please select a file by clicking the 'Browse' button and press 'Upload' to start uploading your file.</p>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<input name="theFile" type="file" />
<input name="Submit" type="submit" value="Upload">
</form>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Id appreciate it if you could elaborate on how the code would be with either POST or GET.
This does not happen when I use the script to upload through the form, so why would it in this case.
Ive attached the s3-class if that can make you sure.
Open in new window