Jump to content

Help needed. User uploads file, then re-direct user back to previous page


devster

Recommended Posts

Hi folks,

 

I was wondering if someone could help me. This is more of a feature than a necessity for my website, but it would be nice.

 

Basically, I have an upload form where users can upload certain files to the site. We've all seen it. I want it so that after the upload is either successfully uploaded or they get the 'wrong file type' error, I want to either re-direct them back to the home page or back to the uploads page automatically, or within 5 seconds or something.

 

The uploads section is fairl straighforward. Here is some of the offending code:

 

The form:

 

<form action="upload.php" method="post" enctype='multipart/form-data'>

<input type="file" name="myfile"><p>

<input type="submit" value="Upload">

 

</form>

 

The php script that checks everything:

 

<?php

 

//Properties of uploaded file

$name = $_FILES["myfile"]["name"];

$type = $_FILES["myfile"]["type"];

$size = $_FILES["myfile"]["size"];

$temp = $_FILES["myfile"]["tmp_name"];

$error = $_FILES["myfile"]["error"];

 

if ($error > 0)

die("Error uploading file!");

else

{

//Conditions for the file type

if($type !== "application/octet-stream")

{

die ("Wrong file type. Please use your browser to navigate back");

}

else if($size > 152000000)

{

die ("File too big. Maximum file size is 80Mb");

}

else

{

move_uploaded_file($temp, "uploads/".$name);

echo "Upload complete! Please use your browser to navigate back";

}

}

 

?>

 

Thank you all for your help.

 

Best regards,

 

Dev.

My suggestion would be to popup a new window for your upload form.  Alternatively you could could put it in a div with an iframe, or some variation of same.  Then you can just indicate that the upload is complete.  Make the window small and design it so it looks like a normal modal dialogue box, and onclick willl just window.close().

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.