Jump to content

Recommended Posts

Hi there. Here is my code: (It is straight from a tutorial site)

Makeaj.php
------------

<form action="makeajcom.php" method="post"><br>
Type (or select) Filename: <input type="file" name="uploadFile">
<input type="submit" value="Upload File">
</form>


Makeajcom.php
---------------


<?php

move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
      "/uploads/{$_FILES['uploadFile'] ['name']}")

?>


///////////--------------//////////////

I figured it would be easy to get this bit done, but it doesnt seem to be working!
uploads is a directory below both php files..

Any help would be really appreciated



Link to comment
https://forums.phpfreaks.com/topic/16628-cant-get-file-upload-script-working/
Share on other sites

Well because my previous post was way to long and had way to much options, I filtered it a bit and came up with this, It still need some altering though.. but it should work


[code]
<?php
function Upload($File, $UploadFolder='', $NewFilename='', $UploadExtFilter='', $UploadMaxSize='') {
if (substr($UploadFolder, -1) != '/') {
$UploadFolder .= '/';
}
if (!is_dir($UploadFolder)) {
// Error message comes here..., or try to create the folder
}
if (!is_writable($UploadFolder)) {
// Error message comes here..., or make it writable
}
if (is_uploaded_file($File['tmp_name'])) {
$Filesize = $File['size'];
$Filename = $File['name'];
if (!preg_match('/\\.('.$UploadExtFilter.')$/i', $Filename)) {
if ($Filesize > $UploadMaxSize) {
// file to big..
}
if ($NewFilename) {
$Filename = $NewFilename;
}
if (file_exists($UploadFolder . $Filename)) {
// Oeps already exists...
}
if (move_uploaded_file($File['tmp_name'], $UploadFolder . $Filename)) {
// Success
return true;
} else {
// No success
return false;
}
} else {
// Extensions not allowed
}
}
}

if ($_POST['submit']=='Upload') {
if (Upload($_FILES['uploadIt'], '/upload/', 'my_file.txt', 'bat|com|php', 8000)) {
echo 'jipii';
}
}
?>

<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="uploadIt"> <input type="submit" name="submit" value="Upload">
</form>
[/code]
// THIS IS WORKING UPLOAD SCRIPT , I AM USING IT....
//------------------------------------------------

if(strlen($HTTP_POST_FILES['ufile']['name']) <1)
{
echo ("ERROR ! No file to upload" );
exit();
}


$upload_path = $HTTP_POST_FILES['ufile']['name'];
//echo $upload_path;

/*if(!is_dir($_POST['path1']))
{
echo ' ERROR ! Path not defined properly';
exit();
}*/
$store_dir = "/upload/";

/*if( !is_dir($store_dir) )
{
  echo("Specified directory is not valid... Exiting");
  @unlink($HTTP_POST_FILES['ufile']['tmp_name']);
  exit();
}*/

if( copy($HTTP_POST_FILES['ufile']['tmp_name'],$store_dir.$HTTP_POST_FILES['ufile']['name']) )
{
  echo("Uploaded ".$HTTP_POST_FILES['ufile']['name']." successfully.");
}

/*if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $upload_path))
{
  echo 'FILES ,'.$HTTP_POST_FILES['ufile']['name'].' uploaded successfully';
}*/
else
  {
  echo 'ERROR : error in uploading ';
  }

unlink($HTTP_POST_FILES['ufile']['tmp_name']);
Hey guys, the basics are now complete, however still one last hurdle to tackle,

When the user locates this persons journal page I need to display all the pictures for this journal.
Now when the user uploaded the pictures they were stored in a folder /upload and each picture had the name
of the journaltitle then a number e.g

beachtrip1.jpg beachtrip2.jpg

How do I first check to see if pictures were uploaded and then display them?...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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