/    Sign up×
Community /Pin to ProfileBookmark

Check Before processing

hey..

i am trying to create simple file upload script…
have lil problem… i just want to check if files were selected and field were not left empty.. how can do that?

[CODE]<table width=”500″ border=”0″ align=”center” cellpadding=”0″ cellspacing=”1″ bgcolor=”#CCCCCC”>
<tr>
<form action=”multiple_upload_ac.php” method=”post” enctype=”multipart/form-data” name=”form1″ id=”form1″>
<td>
<table width=”100%” border=”0″ cellpadding=”3″ cellspacing=”1″ bgcolor=”#FFFFFF”>
<tr>
<td><strong>multiple Files Upload </strong></td>
</tr>
<tr>
<td>Select file
<input name=”ufile[]” type=”file” id=”ufile[]” size=”50″ /></td>
</tr>

<tr>
<td align=”center”><input type=”submit” name=”Submit” value=”Upload” /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>[/CODE]

[code=php]
<?php

$random1 = date(‘s’);
$random2 = date(‘G’);
$random3 = date(‘j’);
print “<br>”;
echo $random1;
print “<br>”;
echo $random2;
print “<br>”;
echo $random3;
print “<br>”;
$new = $random1 * $random2 * $random3;
print “<br>”;
echo $new;
print “<br>”;
mkdir (“uploads/$new”, 0777);

//set where you want to store files
//in this example we keep file in folder upload
//$HTTP_POST_FILES[‘ufile’][‘name’]; = upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path1= “uploads/$new/”.$HTTP_POST_FILES[‘ufile’][‘name’][0];

//copy file to where you want to store file

copy($HTTP_POST_FILES[‘ufile’][‘tmp_name’][0], $path1);

//$HTTP_POST_FILES[‘ufile’][‘name’] = file name
//$HTTP_POST_FILES[‘ufile’][‘size’] = file size
//$HTTP_POST_FILES[‘ufile’][‘type’] = type of file
echo “File Name :”.$HTTP_POST_FILES[‘ufile’][‘name’][0].”<BR/>”;
echo “File Size :”.$HTTP_POST_FILES[‘ufile’][‘size’][0].”<BR/>”;
echo “File Type :”.$HTTP_POST_FILES[‘ufile’][‘type’][0].”<BR/>”;
echo “<img src=”$path1″ width=”150″ height=”150″>”;
echo “<P>”;

// Use this code to display the error or success.

$filesize1=$HTTP_POST_FILES[‘ufile’][‘size’][0];

if($filesize1 != 0)
{
echo “We have recieved your files”;
}

else { echo “ERROR…..”; }
}

?>

[/code]

thanks

to post a comment
PHP

11 Comments(s)

Copy linkTweet thisAlerts:
@cs3mwMay 22.2008 — why not consider Bokehs excellent upload script which a sticky in this forum!!! It doesnt need much tweaking to accomadate your needs and is very reliable!
Copy linkTweet thisAlerts:
@LogicOpinionauthorMay 22.2008 — where is that?


you know man i am trying to create a CMS for a photo gallery and now i am working on that.. so...
Copy linkTweet thisAlerts:
@cs3mwMay 22.2008 — if you go out of this page mate into the php forum index page. At the top is a sticky post called Upload images using PHP!! Trust me mate I would scrap that and just concentrate on adapting this to your needs!!! it will do all the functionality your after!!! Failing that use his as a guideline for your own!!
Copy linkTweet thisAlerts:
@LogicOpinionauthorMay 22.2008 — oh, yeah, its very nice CODE:

so i copied it and tried to add some more features for my needs...

no explaning what i want to do..

on every new upload i want to create new directory and upload files in there..

i did it this way:

[code=php]
<?php

// filename: upload.processor.php

// first let's set some variables

// make a note of the current working directory, relative to root.

$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
$number1 = date('G');
$number2 = date('i');
$number3 = date('s');
$new = $number1 * $number2 * $number3;
$newer = $new * $new;
mkdir("$newer", 0777);
// make a note of the directory that will recieve the uploaded file
$uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . '$newer/';

// make a note of the location of the upload form in case we need it
$uploadForm = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.form.php';

// make a note of the location of the success page
$uploadSuccess = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.success.php';

// fieldname used within the file <input> of the HTML form
$fieldname = 'file';


THE REST OF THE CODE

[/code]


it works fine but i get an error with permissions:

[B][COLOR="Red"]An error has occured: receiving directory insuffiecient permission...

The upload form is reloading[/COLOR]
[/B]



as you see i give permissions 0777 when making this DIR.. why does it gives such an error?


Thanks in advacne!
Copy linkTweet thisAlerts:
@LogicOpinionauthorMay 22.2008 — does anyone know the answer?
Copy linkTweet thisAlerts:
@cs3mwMay 22.2008 — Could I just ask why you want to create a new thumbnail for each image? You could insert all the images into one (or more) folders and just insert the name of the image into a database. That would be my suggestion!!
Copy linkTweet thisAlerts:
@LogicOpinionauthorMay 22.2008 — user logs in clicks RUN GALLERY WIZZARD and makes new gallery step by step

  • 1. upload files to the server this file will be stored in new Unique name folder.

  • 2. there will be a text field where user inserts Gallery Title.. which will have link like this .. page=gallery&gallery_id=folder_unique_name gid will read this directory creat thumbs in thumbs folder display it on the page and remove thumbs from thumbs folder. thats it..


  • is that clear?

    thank you for your help.
    Copy linkTweet thisAlerts:
    @cs3mwMay 22.2008 — Ok try the following

    [code=php]mkdir($newer, 0777);[/code]
    Copy linkTweet thisAlerts:
    @LogicOpinionauthorMay 22.2008 — i didi it that way .. but anyway same error ocures... have no idea why

    could this be causes because of that i run my Local Server On Windows?

    i might try it on linux i think. do not you think so?
    Copy linkTweet thisAlerts:
    @cs3mwMay 22.2008 — no not really because my script works on a windows server. I'll have another look through your code. Have you set the permissions for the root folder which will be holding the newly created folders?
    Copy linkTweet thisAlerts:
    @LogicOpinionauthorMay 23.2008 — mmm.. let me try.. i think i did not.
    ×

    Success!

    Help @LogicOpinion 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.25,
    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,
    )...