/    Sign up×
Community /Pin to ProfileBookmark

end-user content creation

I need to create a way to make it possible for end users to create content on a php web page. The content would need to involve uploading PDF files to a specific folder, and then updating a page to link to the PDFs.

I have no idea where to start on this, so any help would be appreciated.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@SMTSAug 24.2011 — If you are a beginner (especially if you are a beginner), you will not want to hand code this. This could be something that could be stretched out to several files of code ranging in the thousands of lines.

Im not saying it's impossible, it would just be [I]really, really[/I] hard. And if you incorrectly edited one of those lines, you would have a major problem debugging.

Instead, you may want to look on the internet for some open-source solutions that you could tinker with to match your needs.

P.S.

You might want to start with this [B]simple[/B] solution:
[code=html]<html>
<body>
<form enctype="multipart/form-data" action="upload.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
Choose a file to upload: <input name="uploaded_file" type="file" />
<input type="submit" value="Upload" />
</form>
</body>
</html>[/code]


and for processing this:
[code=php]<?php
//&#1057;heck that we have a file
if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
//Check if the file is JPEG image and it's size is less than 350Kb
$filename = basename($_FILES['uploaded_file']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
if (($ext == "jpg") && ($_FILES["uploaded_file"]["type"] == "image/jpeg") &&
($_FILES["uploaded_file"]["size"] < 350000)) {
//Determine the path to which we want to save this file
$newname = dirname(__FILE__).'/upload/'.$filename;
//Check if the file with the same name is already exists on the server
if (!file_exists($newname)) {
//Attempt to move the uploaded file to it's new place
if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
echo "It's done! The file has been saved as: ".$newname;
} else {
echo "Error: A problem occurred during file upload!";
}
} else {
echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists";
}
} else {
echo "Error: Only .jpg images under 350Kb are accepted for upload";
}
} else {
echo "Error: No file uploaded";
}
?>[/code]


In this example, I used a .jpg image file upload with a 350kb limit. This will be very easy to edit. (but be sure to edit both the max size set in the html file AND THE PHP FILE!) The maximum upload size should be no bigger than that allowed in your php.ini file. An attacker could try to send you several large files in one request and fill up the file system in which PHP stores the decoded files. To help prevent this from coming a reality, set the post_max_size directive in your php.ini file to the maximum size that you want (must be greater than upload_max_filesize). The default is 10MB. The above should put the file in /uploads of your current directory. I suppose you could then use javascript or more php to add a link to the file.

You may want to add extra security around this.

Sources

OR YOU COULD STILL USE A OPEN-SOURCE SOLUTION.


Good Luck,

Charles
Copy linkTweet thisAlerts:
@corisanauthorAug 24.2011 — Thanks Charles,

This was very helpful. I've still got my work cut out for me, but at least now I'm on the right track.

Cori
×

Success!

Help @corisan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...