Jump to content

Archived

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

swatisonee

Basic File Upload without ftp access

Recommended Posts

Hi,

I need to give 5 users only, a way of uploading reports onto our server , which can then be downloaded by us. These will be either word/excel/jpeg files only.

Currently, they email it to us but we need the files to be accessible on the server itself.

Following is the snippet of scripts i use for email. How can i modify so that instead of being in a temp file, it remains permanently there. I dont want to give these users ftp access to the server.

Thanks !
Swati

File1
===


[code]
<table>
<tr><td>Upload a file:</td><td><input name="userfile" type="file">File size should not exceed 2MB</td></tr><p><p>
</table>
<p> <br><input type="submit" name="submit" value="Submit"> </p> </form>
[/code]


File2
===
[code]

Start of emailing code by posting other info...
if(!($_FILES["userfile"]["name"]==""))
{
    $uploaddir="./send_email/";
    //copy the file to some permanent location which has 777 permissions
    
    if (move_uploaded_file($_FILES["userfile"]["tmp_name"], $uploaddir.$_FILES["userfile"]["name"]))
    {
    echo("<p>File uploaded<p><p>");
    }
    else
    {
    echo ("<p>Error in uploading file! Please try again.<br>");
    if($_FILES['userfile']['error']==1) echo "<font color=red>Error: File size exceeds maximum permissible limit of 2MB</font><p><p>";
    }
}

Rest of emailing code...

File attached: ".$_FILES["userfile"]["name"];

if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Emailssent successfully.";

@unlink($attach);
?> [/code]

Share this post


Link to post
Share on other sites
Simply rename it?

rename("$_FILES["userfile"]["tmp_name"], "permanent location");

Share this post


Link to post
Share on other sites
Is there somewhere in the bit of code you have left out where you define $attach as the upload_dir/file_name?

If so, remove the line that deletes the file from the server

[code]@unlink($attach);[/code]



Share this post


Link to post
Share on other sites
Hi Sanfly,

The unlink bit is in the code for the php mailer - thats why i didnt copy it. I removed it as you suggested but its not working .

a. When we access the folder on the server, how do we know which files the user has uploaded and their names?

Example: Files on server : a.doc, b.xls, c.jpg.

But i cannot view this list or click on it to download.....

b. Since the file is called tmp_name its creating a problem if 2 users simultaneously try to upload....

Thanks.
Swati

Share this post


Link to post
Share on other sites

×

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.