Jump to content

Search the Community

Showing results for tags 'fileupload'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 2 results

  1. Im creating a CMS for my site and in my admin page I have an add page that adds new content to my site LOCATED HERE and have added a few form fields. 2 of these are: IMAGE URL (text box) & UPLOAD IMAGE (select file button) When I fill in all the fileds and select an image using IMAGE URL and hit add article, it works fine and my form is saved to my database and is then displayed on my site. When I fill in all the fileds and select an image using UPLOAD IMAGE and hit add article, it adds the image to my selected folder in my cpanel but DOES NOT ADD TO DATABASE. My question is: How can I get it to add to the database? and save the new images location to the image field on the database? I have followed this tutorial when adding the upload file button to my page. Please do not show me links on how to do this as I already have read through them but I stuggle when it comes to adding this to my code. my add.php code is this. <?php session_start(); include_once('../include/connection.php'); if (isset($_SESSION['logged_in'])){ if (isset($_POST['title'], $_POST['content'])) { $title = $_POST['title']; $content = nl2br($_POST['content']); if (!empty($_POST['image'])) { $image = $_POST['image']; } else { $image = $_POST['imageupload']; if (isset($_FILES['imageupload'])) { $errors = array(); $allowed_ext = array('jpg', 'jpeg', 'png', 'gif'); $file_name = $_FILES['imageupload'] ['name']; $file_ext = strtolower (end (explode ('.', $file_name))); $file_size = $_FILES['imageupload'] ['size']; $file_tmp = $_FILES['imageupload'] ['tmp_name']; if (in_array ($file_ext, $allowed_ext) === false) { $errors[] = 'File extension not allowed'; } if ($file_size > 2097152) { $errors[] = 'File size must be under 2mb'; } if (empty($errors)) { if (move_uploaded_file($file_tmp, 'images/'.$file_name)) { echo 'File uploaded'; } }else{ foreach ($errors as $error) echo $error, '<br />'; } } } $link = $_POST['link']; $category = $_POST['category']; $brand = $_POST['brand']; if (empty($title) or empty($content)) { $error = 'All Fields Are Required!'; }else{ $query = $pdo->prepare('INSERT INTO mobi (promo_title, promo_content, promo_image, promo_link, promo_cat, promo_name) VALUES(?, ?, ?, ?, ?, ?)'); $query->bindValue(1, $title); $query->bindValue(2, $content); $query->bindValue(3, $image); $query->bindValue(4, $link); $query->bindValue(5, $category); $query->bindValue(6, $brand); $query->execute(); header('location: index.php'); } } ?> <?php if (isset($_FILES['Filedata'])) { // And if it was ok if ($_FILES['Filedata']['error'] !== UPLOAD_ERR_OK) exit('Upload failed. Error code: ' . $_FILES['image']['error']); $filename = $_FILES['Filedata']['name']; $targetpath = "../img/news/" . $filename; //target directory relative to script location $copy = copy($_FILES['Filedata']['tmp_name'], $targetpath); } ?> <html> <head> <title>Add Article</title> <link rel="stylesheet" href="../other.css" /> </head> <body> <div class="container"> <a href="index.php" id="logo"><b>← Back</b></a> <br /> <div align="center"> <h4>Add Article</h4> <?php if (isset($error)) { ?> <small style="color:#aa0000;"><?php echo $error; ?></small><br /><br /> <?php } ?> <form action="add.php" method="post" autocomplete="off" enctype="multipart/form-data"> <input type="text" name="title" placeholder="Title" /><br /><br /> <textarea rows="15" cols="50" placeholder="Content" name="content"></textarea><br /><br /> <input name="imageupload" type="file" id="image" placeholder="Imageupload" /> <input type="text" name="image" placeholder="Image" /><br /><br /> <input type="link" name="link" placeholder="Link" /><br /><br /> <input type="category" name="category" placeholder="Category" /><br /><br /> <input type="category" name="brand" placeholder="Brand" /><br /><br /> <input type="submit" value="Add Article" /> </form> </div> </div> </body> </html> <?php }else{ header('location: index.php'); } ?> please help. thanks.
  2. I am using Malsup's jQuery File Upload Progress Bar for visualizing progress bar while uploading files to server. I am using it now at present. I have got the following doubts in this plugin: 1) File uploads even if the progress bar has not achieved 100% 2) If the File size is more than 10 MB, it loads upto 100% in the progress bar and echoes Upload failed! message. Here is the code : <!doctype html> <head> <title>Uploads</title> <style> body { padding: 30px } form { display: block; margin: 20px auto; background: #eee; border-radius: 10px; padding: 15px }[/left][/font][/color] .progress { position:relative; width:400px; border: 1px solid #ddd; padding: 1px; border-radius: 3px; } .bar { background-color: #B4F5B4; width:0%; height:20px; border-radius: 3px; } .percent { position:absolute; display:inline-block; top:3px; left:48%; } </style> </head> <body> <h1>File Upload</h1> <form action="file.php" method="post" enctype="multipart/form-data"> <input type="file" name="myfile[]" multiple><br> <input type="submit" value="Upload File to Server"> </form> <div class="progress"> <div class="bar"></div > <div class="percent">0%</div > </div> <div id="status"></div> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script> <script src="http://malsup.github.com/jquery.form.js"></script> <script> (function() { var bar = $('.bar'); var percent = $('.percent'); var status = $('#status'); $('form').ajaxForm({ beforeSend: function() { status.empty(); var percentVal = '0%'; bar.width(percentVal) percent.html(percentVal); }, uploadProgress: function(event, position, total, percentComplete) { var percentVal = percentComplete + '%'; bar.width(percentVal) percent.html(percentVal); //console.log(percentVal, position, total); }, complete: function(xhr) { status.html(xhr.responseText); } }); })(); </script> <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script> <script type="text/javascript"> _uacct = "UA-850242-2"; urchinTracker(); </script> The form action -> file.php code : <?php $upload_directory = "../users/Files/"; if (move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_directory . $_FILES['userfile']['name'])) { print "<br><br>"; print "<font color='black'>File Uploaded Successfully</font>"; print "<br><br>"; print "<font color='black'>Uploaded File is {$_FILES['userfile']['name']} and its size is {$_FILES['userfile']['size']} bytes </font>"; } else { print "Upload failed!"; } ?> My server settings for File Uploads: post_max_size 1050M 1050M upload_max_filesize 1050M 1050M upload_tmp_dir /tmp /tmp Settings in php.ini : max_execution_time = 30 ; Maximum execution time of each script, in seconds max_input_time = -1 memory_limit = 2000M ; Maximum amount of memory a script may consume (8MB)
×
×
  • 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.